Userform_initialise Vs Userform_Activate

Challis

New Member
Joined
Oct 22, 2017
Messages
21
Hi
I have a code for a userform with a series of combo boxes that are populated from cell ranges.
I get an error when i try and put the code to populate the combo boxes in the initialize sub. So i had to add them under a new sub acitivate
Is there a way to combine these two subs together? Is it necessary?

Private Sub UserForm_Initialize()


'Variable declaration
Dim IdVal As Integer


'Defining the last row in the Data Sheet ad IdVal
IdVal = fn_LastRow(Sheets("Register"))


'Update next available id on the userform
frmData.txtSEQUENCENUMBER = IdVal
End Sub
Private Sub UserForm_Activate()
'Enters ranges for comboboxes
With Worksheets("LOOKUP")
cmbREV.List = .Range("C1:C" & .Range("C" & .Rows.Count).End(xlUp).Row).Value
cmbAREA.List = .Range("D1:D" & .Range("D" & .Rows.Count).End(xlUp).Row).Value
cmbUNIT.List = .Range("E1:E" & .Range("E" & .Rows.Count).End(xlUp).Row).Value
cmbTYPE1.List = .Range("F1:F" & .Range("F" & .Rows.Count).End(xlUp).Row).Value
cmbTYPE2.List = .Range("G1:G" & .Range("G" & .Rows.Count).End(xlUp).Row).Value
cmbPERSON.List = .Range("H1:H" & .Range("H" & .Rows.Count).End(xlUp).Row).Value
End With
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,215,761
Messages
6,126,735
Members
449,334
Latest member
moses007

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