Userform ComboBox

ehcpieterse

Active Member
Joined
Nov 16, 2006
Messages
278
I have a userform that gets values for combo boxes. It has been working perfectly, but I'm getting an error: "Expected variable or procedure". Could someone please explian to me why this is happening?

My code:

Private Sub UserForm_Initialize()
Dim colNum As Long: colNum = Cells(1, Columns.Count).End(xlToLeft).Column
If colNum > 1 Or (colNum = 1 And Range("A1").Value <> "") Then
For i = 1 To colNum
ComboBox1.AddItem Cells(1, i).Value
ComboBox2.AddItem Cells(1, i).Value
Next i
End If
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
*normally* this issue is down to ambiguous naming -- ie something is named twice -- either a module is named the same as the name of a macro or things are being referred to incorrectly.

have you re-named any of your modules ? If you have change them back for test purposes to Module1,2,3 etc... and see if it's resolved.
 
Upvote 0
Thanks, I had named a module incorrectly.

Would you know how to change the text of a toggle button in a user form? For example if it is pressed it shows "On", else "Off"?

Can one change the colours also?
 
Upvote 0
Use the Click event of the Toggle Button itself (if you double click on the control in the userform (in VBA)) you should see the click event automatically -- insert the below

change toggglebutton1 to be the name of your own togglebutton

Code:
Select Case ToggleButton1.Value
    Case True
        ToggleButton1.Caption = "On"
        ToggleButton1.ForeColor = RGB(255, 0, 0)
    Case False
        ToggleButton1.Caption = "Off"
        ToggleButton1.ForeColor = RGB(0,0,0)
End Select
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,194
Members
448,554
Latest member
Gleisner2

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