gototcm
03-25-2017, 08:37 PM
Combobox runs under specific setup conditions. This is simple. When the userform is launched a combobox (pull-down list) is shown with 3 items apple, banana, and orange. The user selects one of the three than hits a button to delete one of the items (I've omitted the code for the command button "delete" here for simplicity).
On sheet 1 in cells A1-A3 are the words Apple, Banana, orange respectively I have a userform1 with one combobox (name in property is cbPick). Below is the code for the combobox and Initialize sub. The initialize sub is to populate the combobox with Apple, Banana, and orange.
Private Sub cbPick_Change()
Dim fruitname As String
fruitname = cbPick.Value
End Sub
Private Sub UserForm_Initialize()
cbPick.List = Worksheets("sheet1").Range("A1", Range("A1").End(xlDown)).Value
End Sub
There is one module whose code is
Sub showtheform()
Load userform1
userform1.Show
End Sub
The userform1 is launched from a button on the worksheet "sheet1" and the button is assigned to the Macro showtheform. This works perfectly. However, if I move the button to another worksheet, the userform won't launch and through debugging the code line cbPick.List= . . . . is causing an error 1004. I don't understand why moving the button from one worksheet to another causes the error. I am sorry but I don't know how to upload this simple VBA code.
On sheet 1 in cells A1-A3 are the words Apple, Banana, orange respectively I have a userform1 with one combobox (name in property is cbPick). Below is the code for the combobox and Initialize sub. The initialize sub is to populate the combobox with Apple, Banana, and orange.
Private Sub cbPick_Change()
Dim fruitname As String
fruitname = cbPick.Value
End Sub
Private Sub UserForm_Initialize()
cbPick.List = Worksheets("sheet1").Range("A1", Range("A1").End(xlDown)).Value
End Sub
There is one module whose code is
Sub showtheform()
Load userform1
userform1.Show
End Sub
The userform1 is launched from a button on the worksheet "sheet1" and the button is assigned to the Macro showtheform. This works perfectly. However, if I move the button to another worksheet, the userform won't launch and through debugging the code line cbPick.List= . . . . is causing an error 1004. I don't understand why moving the button from one worksheet to another causes the error. I am sorry but I don't know how to upload this simple VBA code.