VBA Frustration

cookeetree

Board Regular
Joined
Mar 2, 2015
Messages
53
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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