I am trying to write a code in excel vba.
I want to change the color of the user selected cell when the checkbox is checked.
I have already written this code but it gives the 'object required' error on the line marked.
Sub CheckBox1_Click()    
Dim xRng As Range    
Set xRng = Selection
If CheckBox1.Value = True Then 'This is the error    
    xRng.Interior.Color = vbGreen    
End If
If CheckBox1.Value = False Then    
    xRng.Interior.Color = xlNone    
End If
End Sub
Please help me on how to debug this error. Thanks in advance! :)
 
     
    
 
    