Hello,
I got a Userform which allows to enter Data in Textboxes and load the belonging values in the remaining Textboxes. My Comboboxes are linked, this means when i select a country then the belonging Cities should appear in Comobox City. My Code is working when i remove the option explicit. But now i declared the Variables, the only thing i cant do, is to set a Variable. Excel tells me "Object Variable or With block variable not set, Runtime error 91". Can anyone please help me solve this problem?
Option Explicit
DIM Sheetn As Worksheet
Dim lastcol As long
Dim n As Integer
Dim j As Integer
Sub Userform_Initialize()
sheetn = "Sheet1"
lastcol = Sheets(Sheetn).Cells(1, 10000).End(xlToLeft).Column
For n = 1 To lastcol
Combobox1 = Sheets(Sheetn).Cells(1, n).Value
Me.Controls("Combobox1").AddItem Combobox1
next n
End Sub
There is a second part of Code, its under a Sub Combobox1_Click()
But when i switch it off the error still appears, so i guess its the Userform_Initialize()
regards
I got a Userform which allows to enter Data in Textboxes and load the belonging values in the remaining Textboxes. My Comboboxes are linked, this means when i select a country then the belonging Cities should appear in Comobox City. My Code is working when i remove the option explicit. But now i declared the Variables, the only thing i cant do, is to set a Variable. Excel tells me "Object Variable or With block variable not set, Runtime error 91". Can anyone please help me solve this problem?
Option Explicit
DIM Sheetn As Worksheet
Dim lastcol As long
Dim n As Integer
Dim j As Integer
Sub Userform_Initialize()
sheetn = "Sheet1"
lastcol = Sheets(Sheetn).Cells(1, 10000).End(xlToLeft).Column
For n = 1 To lastcol
Combobox1 = Sheets(Sheetn).Cells(1, n).Value
Me.Controls("Combobox1").AddItem Combobox1
next n
End Sub
There is a second part of Code, its under a Sub Combobox1_Click()
But when i switch it off the error still appears, so i guess its the Userform_Initialize()
regards