Modify Clear Cells VBA to Multiple Worksheets

Robandemmy

Board Regular
Joined
Jul 16, 2018
Messages
65
I have the following code in place to clear cells the cells on a worksheet named "Production Allocation":

Sub Clear_Cells()

Range("e10:g12").ClearContents
Range("e14:g22").ClearContents
Range("e24:g25").ClearContents
Range("e27:g48").ClearContents
Range("e50:g50").ClearContents
Range("e52:g55").ClearContents
Range("e57:g60").ClearContents
Range("e62:g62").ClearContents
Range("d2:d2").ClearContents

End Sub

I would like to add a few lines to clear cells F65:H65 and F67:H67on worksheet "Labour summary" as well
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
To give an example of how to do it for a named sheet:

Code:
With Sheets("Production Allocation")
    .Range("e10:g12").ClearContents
End With
 
Upvote 0
Try:
Code:
Sub Clear_Cells()
    Sheets("Production Allocation").Range("E10:G12,E14:G22,E24:G25,E27:G48,E50:G50,E52:G55,E57:G60,E62:G62,D2").ClearContents
    Sheets("Labour summary").Range("F65:H65, F67:H67").ClearContents
End Sub
 
Upvote 0
Try this:

Code:
Sub Clear_Cells()
'Modified  11/19/2018  11:11:58 AM  EST
Application.ScreenUpdating = False
With Sheets("Production Allocation")
    .Range("e10:g12").ClearContents
    .Range("e14:g22").ClearContents
    .Range("e24:g25").ClearContents
    .Range("e27:g48").ClearContents
    .Range("e50:g50").ClearContents
    .Range("e52:g55").ClearContents
    .Range("e57:g60").ClearContents
    .Range("e62:g62").ClearContents
    .Range("d2:d2").ClearContents
End With

With Sheets("Labour summary")
    .Range("F65:H65").ClearContents
    .Range("F67:H67").ClearContents
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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