What's wrong with this VB code in Excel?

Soldato
Joined
29 Jan 2004
Posts
3,473
Location
Earth
I'm trying to assign this macro script to a button. So when I press it, it finds the selected radiobutton, copys the value of the relevant cell and pastes (paste special) it into another..

Code:
Sub copy1()
'
' copy1 Macro
'


If ActiveSheet.OptionButton25.Value Then
 Range("J16").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("G10").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
If ActiveSheet.OptionButton26.Value Then
Range("J17").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("G10").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
If ActiveSheet.OptionButton27.Value Then
Range("J18").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("G10").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
If ActiveSheet.OptionButton28.Value Then
Range("J19").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("G10").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Else
    TextBox7.ForeColor = vbBlack
    TextBox7.Font.Bold = True

End If
End If
End If
End If
End Sub

It gives this error: "run time error '438' object doesn't support this property or method"

Any ideas?

Thanks
 
I'm not an expert on VB, but two things are noticeable.

Will checking value provide you with a boolean? Perhaps you should compare value to a non-empty string? (If obj.Value <> "")

Also, have you tried elseifs instead of just ifs?
 
Back
Top Bottom