ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to work with all items in a listbox (https://www.excelbanter.com/excel-programming/445286-how-work-all-items-listbox.html)

SS[_5_]

how to work with all items in a listbox
 
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



John Coleman

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



All times are GMT +1. The time now is 03:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com