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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,873
Messages
6,127,470
Members
449,384
Latest member
purevega

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