Why am I getting a type mismatch?

  • Thread starter Thread starter darius
  • Start date Start date
D

darius

Hi

Extreme newbie here. I don't know why I'm getting a type mismatch error
on this function

Private Function opt_to_text(acol As Integer) As String ' <-- error here
Dim optCheck As MSForms.OptionButton
For x = acol To acol + 3
Set optCheck = "OptionButton" & CStr(x)
If optCheck.Value = True Then
opt_to_text = optCheck.Caption
End If
Next x
End Function

msgbox(opt_to_text(1))

thanks
 
If on a userform:

Private Function opt_to_text(acol As Integer) As String ' <-- error here
Dim optCheck As MSForms.OptionButton
For x = acol To acol + 3
Set optCheck = Controls("OptionButton" & CStr(x))
If optCheck.Value = True Then
opt_to_text = optCheck.Caption
End If
Next x
End Function

If on a worksheet

Private Function opt_to_text(acol As Integer) As String ' <-- error here
Dim optCheck As MSForms.OptionButton
For x = acol To acol + 3
Set optCheck = Activesheet.OleObjects("OptionButton" &
CStr(x)).Object
If optCheck.Value = True Then
opt_to_text = optCheck.Caption
End If
Next x
End Function
 
If on a userform:

Private Function opt_to_text(acol As Integer) As String ' <-- error
here
Dim optCheck As MSForms.OptionButton
For x = acol To acol + 3
Set optCheck = Controls("OptionButton" & CStr(x))
If optCheck.Value = True Then
opt_to_text = optCheck.Caption
End If
Next x
End Function

If on a worksheet

Private Function opt_to_text(acol As Integer) As String ' <-- error
here
Dim optCheck As MSForms.OptionButton
For x = acol To acol + 3


this is it!!
Set optCheck = Activesheet.OleObjects("OptionButton" &
CStr(x)).Object

thanks :)
 
Back
Top