Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping Through Sheets in Excel?? Help please..

Status
Not open for further replies.

bDreamie

Technical User
Oct 23, 2001
8
US
Hi all, I have a problem with VB in Excel. I'm trying to loop through sheets to pick up information and consolidate into another main sheet.

My sheets names are by dates for the month, eg T01-Nov-01, T02-Nov-01, T05-Nov-01 etc. Dates are only for working days in the month (from 01-31 of the month.), therefore the dates will skip the weekends. I need to do a month-end consolidation by going to the data sheets (looping through them) to cut some info and paste it into a consolidated sheet.

How can I going about loop through the sheets, such that when coming to a weekend, it automatically skip if it cannot find the sheet? The day is running, but the prefix T, Month and Date is constant for the month. Is there any other methods of going about this?

Thanks a lot :)
 
to get you started...

Sub test()
Dim oSheet As Worksheet

Dim i As Long

For i = 1 To 31
On Error Resume Next
Set oSheet = ActiveWorkbook.Sheets("T" & Format$(i, "00") & "-nov-01")
On Error GoTo 0
If oSheet Is Nothing Then
Else
Debug.Print oSheet.Name
End If
Set oSheet = Nothing
Next i

End Sub
 
Thanks a lot for your help. I tried this out but there is an error on data type. I did the following before next i.

Sheets(oSheet).Select

Is sthg wrong with this line?

Also I will like to vary the month and year, such that for December I need not change the macro. Can I do a "wildcard" or similar thing for the month and year?

Thanks again :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top