Currently, my comboBoxes and TextBoxes in Excel VBA userform start out blank. One must click on the arrows to see the choices. How can I have the boxes show a default choice?
Use the Userform_Initialise command to set the default values of your various input boxes.
With the VBE open, click on your user-form to see the code (or use the right click function). Select the action "Initialise" in the top right hand box to create a private sub Userform_Initialise.
Write code such as
with me
.MyComboBox.value = "My Default Value"
.MyListBox.value = "First Record"
.MyCaption.caption = "Hello"
end with
When the userform initialises (loads) then the code will run and the default values will be set.
I have tried the above code and with many permutations, but I cannot get it to work in Excel (although most likely a function of me rather than the code). Thanks for the help anyways.
Hi Richard,
for list and combo box use [tt].ListIndex[/tt] property, set =0 for 1st element, =1 for 2nd, etc. If =-1 no item is selected. Use to set/get element.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.