Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Loop through sheets and create a small PivotTable on each


Sub CreatePivots()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If InStr(1, sh.Name, "Sheet1") Then
sh.Select False
Else
sh.Select
Columns("A:J").Select
Selection.Insert Shift:=xlToRight
Range("K1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
ActiveSheet.Range("K1").CurrentRegion).CreatePivot Table _
TableDestination:=ActiveSheet.Range("A1"), TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("DESCRIPTION")
..Orientation = xlRowField
..Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataFiel d ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("TRAN-AMOUNT"), "Sum of TRAN-AMOUNT", xlSum
End If
Next sh
End Sub


The code fails on this line:
sh.Select

Of course I tried this:
sh.Select True

Still fails. If I F8-through I can see that True = True, so I can't figure
out why the code doesn't run. Does anyone see something that I'm not seeing?

TIA,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Loop through sheets and create a small PivotTable on each

sh.Activate ?

Tim


"ryguy7272" wrote in message
...
Sub CreatePivots()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If InStr(1, sh.Name, "Sheet1") Then
sh.Select False
Else
sh.Select
Columns("A:J").Select
Selection.Insert Shift:=xlToRight
Range("K1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
ActiveSheet.Range("K1").CurrentRegion).CreatePivot Table _
TableDestination:=ActiveSheet.Range("A1"), TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("DESCRIPTION")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataFiel d
ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("TRAN-AMOUNT"), "Sum of TRAN-AMOUNT", xlSum
End If
Next sh
End Sub


The code fails on this line:
sh.Select

Of course I tried this:
sh.Select True

Still fails. If I F8-through I can see that True = True, so I can't
figure
out why the code doesn't run. Does anyone see something that I'm not
seeing?

TIA,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Loop through sheets and create a small PivotTable on each


Finally got it:

Sub CreatePivots()
For Each sh In Worksheets
If (sh.Name) < "Sheet1" Then
sh.Select
Columns("A:J").Select
Selection.Insert Shift:=xlToRight

'etc., etc., etc.

End If
Next sh
End Sub

Hope this helps others...

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"ryguy7272" wrote:

Sub CreatePivots()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
If InStr(1, sh.Name, "Sheet1") Then
sh.Select False
Else
sh.Select
Columns("A:J").Select
Selection.Insert Shift:=xlToRight
Range("K1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
ActiveSheet.Range("K1").CurrentRegion).CreatePivot Table _
TableDestination:=ActiveSheet.Range("A1"), TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("DESCRIPTION")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataFiel d ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("TRAN-AMOUNT"), "Sum of TRAN-AMOUNT", xlSum
End If
Next sh
End Sub


The code fails on this line:
sh.Select

Of course I tried this:
sh.Select True

Still fails. If I F8-through I can see that True = True, so I can't figure
out why the code doesn't run. Does anyone see something that I'm not seeing?

TIA,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.

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 to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
How to create copy & paste loop--rows to new sheets MFR Excel Programming 0 October 25th 06 07:50 PM
How to loop through PivotTable ShadowVixen Excel Programming 5 August 4th 06 03:08 AM
Excel prints some sheets very small maybelline5 Excel Discussion (Misc queries) 0 April 22nd 05 07:30 PM


All times are GMT +1. The time now is 05:31 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"