Compile error with If statement on radiobutton.value

257 Views Asked by At

I'm trying to perform an action 'if a radioboxed have been checked", but I'm getting an error:

Compile error: Method or data member not found.

I've created a userform with four radiobuttons (using Controls toolbox), and a commandbutton. The userform loads in an excelsheet (with the click of a separate button), and it is possible to check the radiobutton. if the radiobutton is checked and I click the command button I want some action to happen, but it wont compile my code.

Private Sub cmdCSV_Click()

    Dim JurBen As Integer

    With Thisworkbook

        If .lblRKinst.Value = True Then
            JurBen = 1 
            MsgBox "hurray"
        ElseIf .lblRKkon.Value = True Then
            JurBen = 2 
        ElseIf lblForinst = True Then
            JurBen = 3 
        ElseIf lblForkon = True Then
            JurBen = 4 
        Else: Exit Sub

        MsgBox ("Choose an option")

End If

It seems to dislike the "value" statement, which works fine with checkboxes? I've tried with "enabled" and without anything. I seem to be the only person on the internet with this problem...

As I've used loads of time on this tiny issue, and seem to be stuck, any help would be greatly appreciated!

2

There are 2 best solutions below

0
On

As written by Matteo NNZ I was simply referencing the label and not the radiobutton next to it.

No problem what so ever, as the code above works fine.

0
On

If the Radioboxes are on UserForm then if you want to check their value then 1. the UserForm must be loaded at that time and 2. you need to refer to the UserForm.

Example:

if UserForm1.OptionButton1.Value = true then

The radiobox (OptionButton1 in my example) is member of UserForm and not of ThisWorkbook.