How to clear range in selected multiple worksheet

czarpogi

New Member
Joined
Mar 21, 2017
Messages
7
Hi,

I need some help in making this code short and simple. Is there a way to do that? Thanks in advance.

Here's my code:

Code:
Sub ClearData()
With Sheets("NPS")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With Sheets("QFY")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With Sheets("MFY")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With Sheets("W1")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With Sheets("W2")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With Sheets("W3")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With Sheets("W4")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
With Sheets("W5")
    .Range("A2", .Cells(.Rows.Count, .Columns.Count)).ClearContents
End With
End Sub
[code/]
 
It works! Yes!!!.

THANK YOU SO MUCH! YOU'RE AWESOME MICHAEL!!!

;)

No MAIT....cant test....don't have excel....so may not work !!

AAHHH....just realised....range needs to be cells


Code:
Sub MM1()
Dim sh As Variant
For Each sh In Array("NPS", "QFY", "MFY", "W1", "W2", "W3", "W4", "W5")
Sheets(sh).Activate
Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).ClearContents
Next sh
End Sub
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,216,110
Messages
6,128,892
Members
449,477
Latest member
panjongshing

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