ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   moving through sheets in a loop (https://www.excelbanter.com/excel-programming/361462-moving-through-sheets-loop.html)

Knox

moving through sheets in a loop
 
I have a loop that moves through sheets as "i" changes in a loop. I have
sheets named 1,2,3,4,5 etc. For some reason when I run this I get an error
saying the subscript is out of range for the last line below:

Dim i As Long
Dim startWS As Worksheet
Dim startRange As Range

Set startWS = ActiveSheet
Set startRange = Selection

For i = 3 To 12


startRange.AutoFilter Field:=3, Criteria1:=CStr(i)
Selection.AutoFilter Field:=7, Criteria1:="Monday"
Cells.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("i").Select

Any suggestions? thank you!


[email protected]

moving through sheets in a loop
 
You have i in quotes, which makes it a string - try it as

sheets(i).select


Knox

moving through sheets in a loop
 
Thank You!

" wrote:

You have i in quotes, which makes it a string - try it as

sheets(i).select




All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com