LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Pivot table with a variable range in the sourcedata field

Hi

I need to use a variable in this code to changue de range data used to
create a pivot table.

I would need to include the variable s in stead of using R70 in the
line below:

SourceData:= _
"Sheet1!R1C1:R70C5"


This is the whole code:

Private Sub CommandButton3_Click()
Dim i As Double
Dim s As Double
Dim r As String

i = 1
s = 0

'find the last row with data


Do While i < 2998

If Sheet1.Cells(i, 1) = 0 Then
i = i + 1
If Sheet1.Cells(i, 1) = 0 Then
s = i - 2
GoTo f:
End If
Else
i = i + 1
End If
Loop

f:
' create de pivot table



ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Sheet1!R1C1:R70C5").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddFields
RowFields:=Array( _
"Schedule Group", "Sub Group"), ColumnFields:=Array("Year",
"Build Week")
ActiveSheet.PivotTables("PivotTable1").PivotFields ("SumOfQty
Outstanding"). _
Orientation = xlDataField
End Sub


Can anybody help me please.
I can't find the way to do it.

Thanks

 
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
Display the source for a pivot table page field Gary Brown Excel Worksheet Functions 4 November 8th 06 03:02 PM
Increasing the Source Data range for an existing Pivot Table Shams Excel Worksheet Functions 2 October 10th 06 05:22 PM
Using a Pivot Table Calculated Field to get a Unique Count Mike Struckman Excel Worksheet Functions 1 November 22nd 05 05:32 PM
pivot table sort entries that don't yet appear in table rachael Excel Discussion (Misc queries) 11 September 19th 05 11:29 PM
How can I show all field data in a pivot table, instead of blank Alastair Scott Excel Discussion (Misc queries) 3 August 17th 05 07:08 PM


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