Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default relative reference pivot table macro

Hi,
Every month, I create the same pivot table from a data sheet and every
month, the number of row is different.

I want to record the macro to do this.

When I record the macro and i select my source range, using shift+end+ right
and then shift+end+down, the macro records the cell range as an absolute
value.

If i use the relative reference button when i start the recording, it still
records it using absolute refs

The below is a recording with the relative reference button clicked

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'AP Data'!R1C1:R10077C20").CreatePivotTable TableDestination:="",
TableName _ :="PivotTable8", DefaultVersion:=xlPivotTableVersion10

The only way I can think to do it is highlighting all columns but that adds
a blank value to my pivot table when its complete. I know i can then
deselect it but thats beside the point.

Any ideas? I did try to declare a variable as a changeable range of cells
and using that in the pivot table source cache but couldnt get it working.

I am a complete novice at VBA I have to add.
Thanks
Rob

--
Rob Gaffney
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default relative reference pivot table macro

Hi Rob

Try naming your data as a dynamic range and then referencing the range name
in your pivot data.

e.g. if you name your data range as myDataRange
change your code to

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"=myDataRange").CreatePivotTable TableDestination:="",
TableName _ :="PivotTable8", DefaultVersion:=xlPivotTableVersion10

To name a dynamic range see Debra Dalgleish's Contextures here...
http://www.contextures.com/xlNames01.html#Dynamic

HTH
Trevor Williams




"Gaffnr" wrote:

Hi,
Every month, I create the same pivot table from a data sheet and every
month, the number of row is different.

I want to record the macro to do this.

When I record the macro and i select my source range, using shift+end+ right
and then shift+end+down, the macro records the cell range as an absolute
value.

If i use the relative reference button when i start the recording, it still
records it using absolute refs

The below is a recording with the relative reference button clicked

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'AP Data'!R1C1:R10077C20").CreatePivotTable TableDestination:="",
TableName _ :="PivotTable8", DefaultVersion:=xlPivotTableVersion10

The only way I can think to do it is highlighting all columns but that adds
a blank value to my pivot table when its complete. I know i can then
deselect it but thats beside the point.

Any ideas? I did try to declare a variable as a changeable range of cells
and using that in the pivot table source cache but couldnt get it working.

I am a complete novice at VBA I have to add.
Thanks
Rob

--
Rob Gaffney

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 181
Default relative reference pivot table macro

Hi Rob

Try naming your data as a dynamic range and then referencing the range name
in your pivot data.

e.g. if you name your data range as myDataRange
change your code to

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"=myDataRange").CreatePivotTable TableDestination:="",
TableName _ :="PivotTable8", DefaultVersion:=xlPivotTableVersion10

To name a dynamic range see Debra Dalgleish's Contextures here...
http://www.contextures.com/xlNames01.html#Dynamic

HTH
Trevor Williams




"Gaffnr" wrote:

Hi,
Every month, I create the same pivot table from a data sheet and every
month, the number of row is different.

I want to record the macro to do this.

When I record the macro and i select my source range, using shift+end+ right
and then shift+end+down, the macro records the cell range as an absolute
value.

If i use the relative reference button when i start the recording, it still
records it using absolute refs

The below is a recording with the relative reference button clicked

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'AP Data'!R1C1:R10077C20").CreatePivotTable TableDestination:="",
TableName _ :="PivotTable8", DefaultVersion:=xlPivotTableVersion10

The only way I can think to do it is highlighting all columns but that adds
a blank value to my pivot table when its complete. I know i can then
deselect it but thats beside the point.

Any ideas? I did try to declare a variable as a changeable range of cells
and using that in the pivot table source cache but couldnt get it working.

I am a complete novice at VBA I have to add.
Thanks
Rob

--
Rob Gaffney

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default relative reference pivot table macro

Try this

Sub CreateTbl()
Set Source = Sheets("AP Data").Range("A1")
Region = Source.CurrentRegion _
.Address(external:=True, ReferenceStyle:=xlR1C1)

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:=Region).CreatePivotTable _
TableDestination:="", _
TableName:="PivotTable8", _
DefaultVersion:=xlPivotTableVersion10

End Sub


"Gaffnr" wrote:

Hi,
Every month, I create the same pivot table from a data sheet and every
month, the number of row is different.

I want to record the macro to do this.

When I record the macro and i select my source range, using shift+end+ right
and then shift+end+down, the macro records the cell range as an absolute
value.

If i use the relative reference button when i start the recording, it still
records it using absolute refs

The below is a recording with the relative reference button clicked

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'AP Data'!R1C1:R10077C20").CreatePivotTable TableDestination:="",
TableName _ :="PivotTable8", DefaultVersion:=xlPivotTableVersion10

The only way I can think to do it is highlighting all columns but that adds
a blank value to my pivot table when its complete. I know i can then
deselect it but thats beside the point.

Any ideas? I did try to declare a variable as a changeable range of cells
and using that in the pivot table source cache but couldnt get it working.

I am a complete novice at VBA I have to add.
Thanks
Rob

--
Rob Gaffney

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
Macro- Relative reference tb81 Excel Programming 2 September 2nd 08 01:46 PM
Relative reference? in macro TRYING Excel Worksheet Functions 3 November 20th 07 12:00 AM
Relative reference to a table across multiple worksheets Barry Excel Programming 3 October 25th 07 05:41 PM
Copy data from pivot table using relative reference hello Excel Discussion (Misc queries) 5 April 9th 07 04:13 PM
Relative Reference in a Macro DRH Excel Programming 2 December 31st 04 02:20 PM


All times are GMT +1. The time now is 02:07 AM.

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"