Worksheet range in a worksheet array

ChesterKaup

New Member
Joined
Aug 19, 2010
Messages
36
I have a worksheet array and would like to reference the same ranges on each worksheet to do some various thinks on each worksheet as I loop through them. My code fails on the range statement and I am unsure what to do. The .columns statement works fine. Below is the code. Thanks for any help.

For I = 0 To UBound(WorkSheetNames)
With Worksheets(WorkSheetNames(I))
.Columns("G:G").ColumnWidth = 10
.Range("N9:AM9").Select
.Selection.AutoFill Destination:=Range("N9:AM800"), Type:=xlFillDefault
.Range("N2").Select
.Range("N2").Formula = "=AVERAGEIFS(AF9:AF480,AF9:AF480,"">0"",A9:A480, ""<"" &N2)"
.Range("N3").Select
.Range("N3").Formula = "=AVERAGEIFS(AF9:AF480,AF9:AF480,"">0"",A9:A480, "">"" &N2)"
End With
Next I
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
See if this works for you:
Code:
Dim ws As Worksheet
For Each ws In Worksheets
    With ws
        .Columns("G:G").ColumnWidth = 10
        .Range("N9:AM9").AutoFill Destination:=.Range("N9:AM800"), Type:=xlFillDefault
        .Range("N2").Formula = "=AVERAGEIFS(AF9:AF480,AF9:AF480,"">0"",A9:A480, ""<"" &N2)"
        .Range("N3").Formula = "=AVERAGEIFS(AF9:AF480,AF9:AF480,"">0"",A9:A480, "">"" &N2)"
    End With
Next
 
Upvote 0
Try this.
Code:
For I = 0 To UBound(WorkSheetNames)
    With Worksheets(WorkSheetNames(I))
        .Columns("G:G").ColumnWidth = 10
        .Range("N9:AM9").AutoFill Destination:=.Range("N9:AM800"), Type:=xlFillDefault
        .Range("N2").Formula = "=AVERAGEIFS(AF9:AF480,AF9:AF480,"">0"",A9:A480, ""<"" &N2)"
        .Range("N3").Formula = "=AVERAGEIFS(AF9:AF480,AF9:AF480,"">0"",A9:A480, "">"" &N2)"
    End With
Next I
 
Upvote 0

Forum statistics

Threads
1,215,793
Messages
6,126,936
Members
449,349
Latest member
Omer Lutfu Neziroglu

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