Clear cells from specific multiple ranges on sheet

rach_oh

New Member
Joined
Aug 2, 2023
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Trying to clear cell contents from the below ranges on the worksheet & it's giving syntax error

Private Sub CommandButton5_Click()
Worksheets (“Sheet18”)_
.Range("F10:G28").ClearContents
.Range("K38:V56").ClearContents
.Range("F62:G80").ClearContents
.Range("K90:V108").ClearContents
.Range("F116:G134").ClearContents
.Range("K144:V162").ClearContents
.Range("F170:G188").ClearContents
.Range("K198:V216").ClearContents
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Should be:
VBA Code:
Option Explicit
Private Sub CommandButton5_Click()
    With Worksheets("Sheet18")
        .Range("F10:G28").ClearContents
        .Range("K38:V56").ClearContents
        .Range("F62:G80").ClearContents
        .Range("K90:V108").ClearContents
        .Range("F116:G134").ClearContents
        .Range("K144:V162").ClearContents
        .Range("F170:G188").ClearContents
        .Range("K198:V216").ClearContents
    End With
End Sub
 
Upvote 0
Solution
Should be:
VBA Code:
Option Explicit
Private Sub CommandButton5_Click()
    With Worksheets("Sheet18")
        .Range("F10:G28").ClearContents
        .Range("K38:V56").ClearContents
        .Range("F62:G80").ClearContents
        .Range("K90:V108").ClearContents
        .Range("F116:G134").ClearContents
        .Range("K144:V162").ClearContents
        .Range("F170:G188").ClearContents
        .Range("K198:V216").ClearContents
    End With
End Sub
thank you!!
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,263
Members
449,093
Latest member
Vincent Khandagale

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