Userform must be opened twice to populate

JWebb

New Member
Joined
Apr 5, 2017
Messages
17
Hello again and thanks to anyone who reads this. (Excel 2016)
I have a simple userform with 2 combobox's and a command button. The Userform is called from a button on a spreadsheet. The issue is that the combobox's do not populate on the first call. I have to close the UF and then reopen it before it works correctly.

Code:
Sub Button1_Click()


Dim FinalRow As Long
Dim FinalRow2 As Long


UserForm1.Show


FinalRow = Worksheets("Reference").Cells(Application.Rows.Count, 1).End(xlUp).Row
FinalRow2 = Worksheets("Reference").Cells(Application.Rows.Count, 2).End(xlUp).Row


UserForm1.ComboBox1.List = Sheets("Reference").Range("A2:A" & FinalRow).Value
UserForm1.ComboBox2.List = Sheets("Reference").Range("B2:B" & FinalRow2).Value


End Sub

Any help is greatly appreciated.
Thanks
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Move the Userform.show line to the end of the sub
 
Upvote 0
I suggest this:

Put this code in your Userform.

Code:
Private Sub UserForm_Initialize()
'Modified  4/17/2019  2:57:16 PM  EDT
Dim FinalRow As Long
Dim FinalRow2 As Long
FinalRow = Worksheets("Reference").Cells(Application.Rows.Count, 1).End(xlUp).Row
FinalRow2 = Worksheets("Reference").Cells(Application.Rows.Count, 2).End(xlUp).Row
UserForm1.ComboBox1.List = Sheets("Reference").Range("A2:A" & FinalRow).Value
UserForm1.ComboBox2.List = Sheets("Reference").Range("B2:B" & FinalRow2).Value
End Sub

And put your:


Userform1.show only in your Button click.
 
Last edited:
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,720
Messages
6,126,439
Members
449,314
Latest member
MrSabo83

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