I'm trying to do a VBA userform with a dynamic ComboBox - using dynamic named ranges. It should read the columns from sheet1 and populate the ComboBoxes.
However, when I run the userform I'm getting a 'Runtime Error: 1004 - Application Defined or Object Defined Error'.
Any ideas how I fix this? I'm not an experienced coder, so be gentle with me
In sheet1, where I have the lookup values for the combo boxes, I have:
The code for the userform is:
Thanks for any help....
However, when I run the userform I'm getting a 'Runtime Error: 1004 - Application Defined or Object Defined Error'.
Any ideas how I fix this? I'm not an experienced coder, so be gentle with me
In sheet1, where I have the lookup values for the combo boxes, I have:
Where | Location | Event_Type |
Where1 | Loc1 | Type1 |
Where2 | Loc2 | Type2 |
Where3 | Loc3 | Type3 |
Where4 | Loc4 | Type4 |
Where5 | Loc5 | Type5 |
Loc6 | Type6 | |
Type7 | ||
Type8 | ||
Type9 |
The code for the userform is:
VBA Code:
Private Sub UserForm_Initialize()
Dim lastrow As Long
Dim lastcolumn As Long
Dim i As Integer
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(x1toleft).Column
With Worksheets("sheet1")
For i = 1 To lastcolumn
With .Columns(i)
lastrow = Sheet1.Cells(Rows.Count, i).End(x1up).Row
With Range(Cells(1, i), Cells(lastrow, i))
Range(Cells(1, i), Cells(lastrow, i)).Select
Selection.CreateNames Top:=True
End With
End With
Next i
End With
'Just doing the 1st ComboBox to start with
Me.ComboBox1.RowSource = "Where"
End Sub
Thanks for any help....