Is there any way that a CommandButton can be used to scroll a selection of ListBox items?
All are contained within a UserForm and the ListBox items are drawn from a dymanic list in a specified folder.
Is there any way that a CommandButton can be used to scroll a selection of ListBox items?
All are contained within a UserForm and the ListBox items are drawn from a dymanic list in a specified folder.
What are you trying to achieve?
Excel inserts Horizontal and Vertical scroll Bars into the Listbox as needed.
Are you saying that you want to highlight a specific entry as you scroll down?
My General Rules if you want my help. Not aimed at any person in particular:
1. Please Make Requests not demands, none of us get paid here.
2. Check back on your post regularly. I will not return to a post after 4 days.
If it is not important to you then it definitely is not important to me.
Hi mehmetcik,
Yes, When I click a button I would like to select the 1st entry in the ListBox and then with each subsequent click I would like the ListBox to select the next entry, and so on, in a loop.
Can that be achieved?
Thank you,
Andy
Hi there,
See if the attached workbook does what you need.
It uses the following code in the VBA CodeModule of the UserForm:
and the following code in a standard VBA CodeModule:Please Login or Register to view this content.
Please Login or Register to view this content.
Hope this helps - please let me know how you get on.
Regards,
Greg M
Try this Code
Please Login or Register to view this content.
A Spinbutton or a Scrollbar are better for this:=
Please Login or Register to view this content.
Last edited by mehmetcik; 02-19-2019 at 02:06 PM.
Thanks for the replies...ukuini, you are correct, lost in translation there I think, apologies...
I have had a look through the responses and I agree that a spinbutton or similar would likely be most suitable, but have the following observations if someone can assist?
I have attached an example workbook and some images within a folder structure replicating what I have.
The relevant filepath for the images will need to be replicated in the code.
I am encountering the following problems at the moment,
1 - Upon clicking the right spinbutton the first entry in Listbox1 is not selected, and,
If image#2 "sid" is selected in Listbox1, where "bird" is selected in Combobox1, then Combobox1 is changed to "cat", clicking the right spinbutton loads image#3 "spider", and so on...it's like the listbox value needs to be reset each time combobox1 is changed.
2 - If the last entry in Listbox1 is selected with the Combobox1 selections "cat" or "dog" and the Combobox1 selection is changed to the preceding value, i.e. "bird" or "cat" respectively, and the left spinbutton is clicked, all is well, however if the right spinbutton is clicked the following error is produced,
Any ideas would be most welcome...Run-time error '380':
Could not set the Selected property. Invalid property value.
Thank you
*** Bump ***
Try this:
Note that I moved the root folder path to a constant at the top so you only need to alter it in one place.Please Login or Register to view this content.
Rory
Hi rorya
I was getting the same error message when I selected an entry in the ComboBox I couldn't understand why. Then I realised that in the version I am running one of the ComboBox entries didn't have any images attached which would populate the ListBox, hence the ListIndex would have to be -1 rather than 0, so it was crashing out at the line.Please Login or Register to view this content.
I've fixed it by wrapping that section in an If command, checking that the ListBox is populated before continuing, I'm guessing that is the most convenient way to solve my particular problem?
Yes, that seems quite reasonable.
Ha! Cool Thank you all for your help. I've got another question but that's for another post I think...
Hi again,
Many thanks for your private message and also for the Reputation increase - much appreciated!
You're welcome - glad to hear that everything seems to be working correctly now.
Best regards,
Greg M
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks