Listbox Question

Lamar in Houston

Board Regular
Joined
Jan 21, 2006
Messages
72
Greetings all

I have a listbox on a userform that contains a list of names. My intent is that the user scroll the names in the listbox until the one needed is found. Then the user will click a command button to process info for the name. The problem I am having is that unless the user clicks on the name after scrolling to find it, the data is processed without the name.

Is there a way for the data in the listbox to be active without the user clicking on the name>

Thanks

Lamar
 
I don't believe that is possible. Although you could use the .listindex property in place of the .value property, both properties require the user to click in th elistbox in order to be updated. if you try to process without a user click in th elist, then .value will be a default value of Nothing, and .listindex will be -1, inless you have set these to some value in code. There is no way that I know of that you can determine what name is currently diplayed at the top of the list.

The only way that I can think of to get around it is to use a Spinbutton control to index the .listindex property up or down based on the click event. This would have the effect of moving the highlight bar up and down within the list, but my opinion is that this woul dcause an awful olot of confusion, as it would appear in addition to the native scrollbar of the listbox... unless you size it appropriately to cover the scrollbar of the listbox.

Is there some reason why you couldn't move your code from the CommandButton to the Click event of the ListBox?
 
Upvote 0
Thank you for your response. I had come to the same conclusion, but your reply gave me an idea. I have put in an error trap to catch occurances where the name is = " ". The msgbox prompts them to click on the name selected.

There aree other fields which the users have to make choices on prior to the update so I chose not to use the click event to run the macros.

Again, thanks for your response & help

-Lamar
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top