VBA Frustration

cookeetree

Board Regular
Joined
Mar 2, 2015
Messages
52
G'day Excel Gods,

I'm trying to run what should be simple code to clear the contents of a range when a checkbox is ticked.

The checkbox is linked to cell D33.

Sub OneforOne_CheckBox()

If Range("D33") = True Then
Range.("L34:U41").ClearContents
End If

End Sub

The code keeps failing on the middle line.
I've tried changing the range to include the worksheet name - Worksheets("Compaction1").Range.("L34:U41").ClearContents - but it still fails.
Where am I going wrong??? It's driving me nuts!

Any assistance you could provide would be greatly appreciated.

Cheer, Jason.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Range.("L34:U41").ClearContents
There's a period after "Range" on this line. Try removing it.
Also, you don't need the "=True" in the condition check. It's already a boolean.

VBA Code:
Sub OneforOne_CheckBox()
    If Range("D33").Value Then
        Range("L34:U41").ClearContents
    End If
End Sub
 
Upvote 1
Solution
There's a period after "Range" on this line. Try removing it.
Also, you don't need the "=True" in the condition check. It's already a boolean.

VBA Code:
Sub OneforOne_CheckBox()
    If Range("D33").Value Then
        Range("L34:U41").ClearContents
    End If
End Sub
Thank you for your help. That single period was my downfall! Man, that was driving me crazy!!

The first line works with either the original code or your revision.

Thanks again. Case closed. (y)
 
Upvote 0

Forum statistics

Threads
1,215,262
Messages
6,123,939
Members
449,134
Latest member
NickWBA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top