LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Modify Pivot Table SourceData range

I have 10 worksheets of data each with a pivot table(1) on them. New data is
added each month to each sheet. My routine loops through each sheet, cleans
out blank rows and copies the new data to a master sheet "Data". How do I
modify the new data range for the pivot tables? My last line of code creates
a new pivot table, which is not what I want of course. And then finally to
refresh the tables. Does ActiveWorkbook.RefreshAll work on pivot tables
also?

Sub CleanUp()
Dim ws As Worksheet
Dim DRow As Long, SRow As Long
Dim DRng As Range, SRng As Range
Dim c As Range, shrng As Range
Dim i As Integer

DRow = Worksheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
If DRow < 3 Then DRow = 3
Set DRng = Worksheets("Data").Range("A3:G" & DRow)
DRng.Delete

For i = 3 To 12
Set ws = Worksheets(i)
SRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
Set shrng = ws.Range("B3:B" & SRow)
For Each c In shrng
If c.Value = "" Then ws.Range(c.Offset(0, -1), c.Offset(0,
4)).Delete
Next c
SRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
Set SRng = ws.Range("A3:E" & SRow)
DRow = Worksheets("Data").Cells(Rows.Count, "A").End(xlUp).Row
If DRow < 2 Then DRow = 2
Set DRng = Worksheets("Data").Range("B" & DRow + 1)
SRng.Copy DRng
DRow = Worksheets("Data").Cells(Rows.Count, "B").End(xlUp).Row
Set DRng = Worksheets("Data").Range("A3:A" & DRow)
DRng.Value = ws.Name
Set SRng = ws.Range("A1:F" & SRow)
'ws.PivotTableWizard SourceType:=xlDatabase, SourceData:=SRng

Next i
End Sub


 
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
Pivot table with a variable range in the sourcedata field [email protected] Excel Discussion (Misc queries) 2 January 31st 07 12:11 AM
Pivot Table sourcedata string truncation John B[_3_] Excel Programming 0 January 27th 06 05:49 AM
Modify Pivot Table Page Field DynamiteSkippy Excel Programming 2 May 28th 05 02:42 AM
SourceData in pivot table JIM.H.[_2_] Excel Programming 0 June 9th 04 12:59 AM
Dynamic Array as pivot table SourceData..? Robert Stober Excel Programming 0 October 3rd 03 05:36 PM


All times are GMT +1. The time now is 01:39 AM.

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

About Us

"It's about Microsoft Excel"