ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Any more effective method to get selected item in Listbox? (https://www.excelbanter.com/excel-programming/439198-any-more-effective-method-get-selected-item-listbox.html)

Danny[_13_]

Any more effective method to get selected item in Listbox?
 
Hi,

I have a question about the Userform.listbox

I would like to make a userform, which has 2 listbox. The first one
(listbox1) is showing the sheet name in workbook. Another (listbox2)
is showing the range(cells(1,1),cells(1,1).end(xltoright).column) of
select sheet name (selected at listbox1)

my normal practice to get selected item in listbox is below. Any more
effective method?
_______________________________________
k = userform.lisbox1.ListCount
j = 1
For i = 1 To k
If userform.lisbox1.Selected(i - 1) = True Then
ReDim Preserve Array(j)
Array(j) = i
j = j + 1
End If
Next i
_______________________________________

joel[_643_]

Any more effective method to get selected item in Listbox?
 

[either Value or Text will get the data. Listindex will get the item
numbver in the list with the first one = 0. Setting ListIndex to -1
will deselect all items.


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=176311

Microsoft Office Help


Bob Phillips[_4_]

Any more effective method to get selected item in Listbox?
 
Listbox1.Value

HTH

Bob

"Danny" wrote in message
...
Hi,

I have a question about the Userform.listbox

I would like to make a userform, which has 2 listbox. The first one
(listbox1) is showing the sheet name in workbook. Another (listbox2)
is showing the range(cells(1,1),cells(1,1).end(xltoright).column) of
select sheet name (selected at listbox1)

my normal practice to get selected item in listbox is below. Any more
effective method?
_______________________________________
k = userform.lisbox1.ListCount
j = 1
For i = 1 To k
If userform.lisbox1.Selected(i - 1) = True Then
ReDim Preserve Array(j)
Array(j) = i
j = j + 1
End If
Next i
_______________________________________




Danny[_13_]

Any more effective method to get selected item in Listbox?
 
Thank you all,

how about if the selected items is more than one? Must need the loop
to determine?

Bob Phillips[_4_]

Any more effective method to get selected item in Listbox?
 
IF more than one, yes you have to loop and pick them out.

HTH

Bob

"Danny" wrote in message
...
Thank you all,

how about if the selected items is more than one? Must need the loop
to determine?





All times are GMT +1. The time now is 03:00 AM.

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