How can I clear a range of cells in multiple worksheets in the same workbook?

haganator

New Member
Joined
Aug 5, 2008
Messages
42
I have a workbook with 14 worksheets in it, and I need to clear contents with the same range in each worksheet. Here is the code that I'm trying to use:

Dim Sht As Worksheet

On Error Resume Next

For Each Sht In ThisWorkbook.Worksheets
Range("C22:H1461").Select
Selection.ClearContents
Range("C22").Select
Next Sht


End Sub

The code only works on the active sheet...I can't get it to go to the next sheet.

Any ideas would be greatly appreciated.

Thanks in advance,
Jeff
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
haganator


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
Option Explicit
Sub Test()
Dim Sht As Worksheet
For Each Sht In ThisWorkbook.Worksheets
  Sht.Activate
  Range("C22:H1461").ClearContents
  Range("C22").Select
Next Sht
End Sub



Or, try, this next piece of code, but this will not work Range("C22").Select :


Code:
Option Explicit
Sub Test2()
Dim Sht As Worksheet
For Each Sht In ThisWorkbook.Worksheets
  Sht.Range("C22:H1461").ClearContents
Next Sht
End Sub
 
Last edited:
Upvote 0
haganator,

Thanks for the feedback.

You are very welcome. Glad I could help.

Come back anytime.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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