View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John Coleman John Coleman is offline
external usenet poster
 
Posts: 274
Default how to work with all items in a listbox

On Jan 22, 1:53*pm, SS wrote:
Hi,
I have a userform that has two listboxes. *Users move selected items
from the listbox1 on the left, to listbox2 on the right. *Items are
text stings like "123456 Enzyme rev 1"
Then, the user will click a command button to execute ops on items
listed in listbox2. *Note that i don't want it to matter if any items
are selected (highlighted) in listbox2. *I need the operation to be
executed on all the items listed in listbox2, looping through one at a
time.

The value (variable) i need for an ensuing operation will be item(s)
in the listbox2, one at a time.

Upon clicking a command button, how do i:

- create a loop that:
- work with the items from the listbox2 one at a time, so i can use
that value to complete an in loop operation step (the ensuing
operation mentioned above).
- once that step is complete, it loops back to the next item in the
listbox2, and continues until all items in the listbox have been gone
through.

Basically, I can't figure out how to work with the items in the
lisbox.
Any help would be much appreciated.

Thanks,
Steve


Maybe this can yet you started:

Private Sub CommandButton1_Click()
Dim i As Long, n As Long
n = ListBox2.ListCount
For i = 0 To n - 1
MsgBox ListBox2.List(i)
Next i
End Sub

Note that within the userform code you do not need a variable to
reference the listbox (assuming that it has already been created) and
that the indexing is zero-based