I have this code to add an option button to a user form from https://analysistabs.com/vba-code/excel-userform/optionbutton/ which seems simple enough, but it gets an error "Type mis-match".
The userform has been added from Insert>UserForm in the editor. The editor only gives one possible option in the statement "Dim OpBtn as OptionButton". So what could go wrong?
Sub Add_Dynamic_OptionButton()
Dim OpBtn As OptionButton
'Add Dynamic OptionButton and assign it to object 'OpBtn'
Set OpBtn = UserForm1.Controls.Add("Forms.OptionButton.1")
'ERRORS HERE
'Assign OptionButton Name
OpBtn.Caption = "Dynamic OptionButton"
'OptionButton Position
OpBtn.Left = 486
OpBtn.Top = 48
End Sub
I'd like to use this code to add an option button. Thanks in advance
Dim OpBtn As msforms.OptionButton.