Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Worksheets in Loop

This is probably simple, but here goes anyway...

I have 7 worksheets with pivot tables and an 8th sheet with detail data.
I've put together code (that works) to define a named range based on the
detail data. I would now like to loop through the other 7 sheets and update
each pivot table (already set to that named range).

Currently, I have simple code that goes to each tab individually, but
looking ahead, I would like to put the code into a loop. Here is what I have
so far...

Dim T1, T2, T3, T4, T5, T6, T7 As String

T1 = "abc"
T2 = "def"
T3 = "ghi"
T4 = "jkl"
T5 = "mno"
T6 = "pqr"
T7 = "stu"

....the loop that I tried (unsuccessfully) looks like...

For x = 1 to 7
Worksheets("T" & x).Activate
Set pvtTable = Worksheets("T" & x).Range("A3").PivotTable
pvtTable.RefreshTable
Next x

....the problem is with the <Worksheets("T" & x) lines - not sure what the
correct syntax would be (I've tried several different ways). Maybe use code
to simply go to the next visible sheet?

Thanks in advance for the help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Worksheets in Loop

Thank you. Makes sense.

"Mike" wrote:

Sub test()
Dim WS_Count As Integer
Dim WS_Name As Worksheet
Dim i As Integer
WS_Count = ThisWorkbook.Worksheets.Count

For i = 1 To WS_Count
MsgBox Worksheets(i).Name
Next i
End Sub

"ReportSmith" wrote:

This is probably simple, but here goes anyway...

I have 7 worksheets with pivot tables and an 8th sheet with detail data.
I've put together code (that works) to define a named range based on the
detail data. I would now like to loop through the other 7 sheets and update
each pivot table (already set to that named range).

Currently, I have simple code that goes to each tab individually, but
looking ahead, I would like to put the code into a loop. Here is what I have
so far...

Dim T1, T2, T3, T4, T5, T6, T7 As String

T1 = "abc"
T2 = "def"
T3 = "ghi"
T4 = "jkl"
T5 = "mno"
T6 = "pqr"
T7 = "stu"

...the loop that I tried (unsuccessfully) looks like...

For x = 1 to 7
Worksheets("T" & x).Activate
Set pvtTable = Worksheets("T" & x).Range("A3").PivotTable
pvtTable.RefreshTable
Next x

...the problem is with the <Worksheets("T" & x) lines - not sure what the
correct syntax would be (I've tried several different ways). Maybe use code
to simply go to the next visible sheet?

Thanks in advance for the help.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop thru worksheets(i) Jim at Eagle Excel Programming 6 April 10th 08 10:14 PM
For/Next Loop through worksheets klysell Excel Programming 7 August 7th 07 07:40 PM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 0 March 27th 07 11:17 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM


All times are GMT +1. The time now is 09:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"