Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA-Looping though MultiSelect on ListBox

I am trying to loop a procedure to run for EACH item selected in
ComboBox.

Basically, I want to populate a spreadsheet based with the value in
textbox from a userform that also contains a ComboBox (this wil
isolate the column) and a listbox (this will isolate the multple row
that need to be populated).

Right now, it will properly populate the LAST item selected in th
listbox, rather than ALL items selected.

My current code is as follows:

Private Sub InsertClassDates()
For i = 1 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then _
r = ListBox1.ListIndex + 2
Select Case True
Case ComboBox1.ListIndex = 0: Cells(r, 6) = TextBox1.Value
Case ComboBox1.ListIndex = 1: Cells(r, 7) = TextBox1.Value
Case ComboBox1.ListIndex = 2: Cells(r, 8) = TextBox1.Value
Case ComboBox1.ListIndex = 3: Cells(r, 9) = TextBox1.Value
Case ComboBox1.ListIndex = 4: Cells(r, 10)
TextBox1.Value
End Select
Next i
Unload UserForm1
End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel VBA-Looping though MultiSelect on ListBox

This was answered previously. For an explantion and some cautions, check
the original answer.

Private Sub InsertClassDates()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
r = i + 2
Select Case True
Case ComboBox1.ListIndex = 0: Cells(r, 6) = TextBox1.Value
Case ComboBox1.ListIndex = 1: Cells(r, 7) = TextBox1.Value
Case ComboBox1.ListIndex = 2: Cells(r, 8) = TextBox1.Value
Case ComboBox1.ListIndex = 3: Cells(r, 9) = TextBox1.Value
Case ComboBox1.ListIndex = 4: Cells(r, 10) = TextBox1.Value
End Select
End if
Next i
Unload UserForm1
End Sub

could also do

Private Sub InsertClassDates()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
r = i + 2
Cells(r,Combobox1.Listindex + 6).Value = Textbox1.Value
End if
Next i
Unload UserForm1
End Sub


--
Regards,
Tom Ogilvy


"jpendegraft " wrote in message
...
I am trying to loop a procedure to run for EACH item selected in a
ComboBox.

Basically, I want to populate a spreadsheet based with the value in a
textbox from a userform that also contains a ComboBox (this will
isolate the column) and a listbox (this will isolate the multple rows
that need to be populated).

Right now, it will properly populate the LAST item selected in the
listbox, rather than ALL items selected.

My current code is as follows:

Private Sub InsertClassDates()
For i = 1 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then _
r = ListBox1.ListIndex + 2
Select Case True
Case ComboBox1.ListIndex = 0: Cells(r, 6) = TextBox1.Value
Case ComboBox1.ListIndex = 1: Cells(r, 7) = TextBox1.Value
Case ComboBox1.ListIndex = 2: Cells(r, 8) = TextBox1.Value
Case ComboBox1.ListIndex = 3: Cells(r, 9) = TextBox1.Value
Case ComboBox1.ListIndex = 4: Cells(r, 10) =
TextBox1.Value
End Select
Next i
Unload UserForm1
End Sub


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA-Looping though MultiSelect on ListBox

Thanks! Worked perfect

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
can I have a multiselect option for a list box in excel 2003 pascaleinlove Excel Discussion (Misc queries) 1 March 15th 10 06:41 PM
Multiselect Listbox use RKS Excel Discussion (Misc queries) 1 May 12th 06 03:04 PM
multiselect listbox CG Rosén Excel Programming 2 December 28th 03 05:17 PM
Multiselect Boxes Jase Excel Programming 2 October 22nd 03 03:40 AM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 07:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"