Clear Array

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Evening all

something simple - maybe someone can explain why the the below errors out




Code:
Sheets(Array("Sheet2", "Sheet3", "Sheet4")).Range("A1").CurrentRegion.Clear
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I have a script which does what I need - however trying to utilize array method.

Code:
Sub DeleteCurrentRegion()

Dim s As Worksheet
For Each s In Worksheets
If s.Name <> "Sheet1" Then
s.Range("A1").CurrentRegion.Clear
End If
Next
End Sub

Thank you for any explanation.
 
Upvote 0
Evening all

something simple - maybe someone can explain why the the below errors out




Code:
Sheets(Array("Sheet2", "Sheet3", "Sheet4")).Range("A1").CurrentRegion.Clear

When you use an array argument of sheet names like that, the assumption is you are doing the same thing to all sheets. My guess... Excel probably assumes the CurrentRegion will (or at least could be) different on each sheet, so it cannot be sure it would be able to do the same thing on each sheet.
 
Upvote 0
Thank You Mr.Rothstein


In this example I am attempting to clear the range which may be different?

Code:
Worksheets(Array("Sheet2", "Sheet3", "Sheet4")).Range("A1" , Range("Z" & Rows.Count).End(xlUp)).Clear
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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