Pivot source data error

krishna334

Active Member
Joined
May 22, 2009
Messages
391
Hi All,

Below is a part of my macro:

Sheets("SUMMARY").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"PM Manual Override!R5C1:R514C61", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="SUMMARY BY PM BY HPL!R4C1", TableName:= _
"PivotTable3", DefaultVersion:=xlPivotTableVersion12


I want to change it as something like below:

Sheets("SUMMARY").Select

K = Sheets("Planner Manual Override").UsedRange.Rows.Count
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
Sheets("PM Manual Override").Range("A5:BI" & K), Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="SUMMARY BY PM BY HPL!A4", TableName:= _
"PivotTable2", DefaultVersion:=xlPivotTableVersion12


What i want is to change the R1C1 type referencing of souce data to something with Range("A5:BI" & K), where K is the last used row of a sheet "Planner Manual Override". But the above modifed one shows error
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
In the first codeblock replace:
"PM Manual Override!R5C1:R514C61",
with:
"PM Manual Override!" & Range("A5:BI" & K).Address(ReferenceStyle:=xlR1C1),
and leave:
SUMMARY BY PM BY HPL!A4
as it is (an RC reference not an A1 reference)

also .UsedRange can yield some bad (usually too large) values which would put rows of blanks in your pivot table.

If the data starts in A1, then either of these should work:
Range("A1").CurrentRegion.Rows.Count or
Range(Cells(Rows.Count,1).End(xlUp).Row (where 1 is the column being counted)
 
Upvote 0
Hi pbornemeier,

Sorry for the late response.
Your code worked. Thanks a lot.

what is and RC reference and A1 reference?
 
Upvote 0
Excel can reference a cell 2 different ways. The newer version (A1) uses a letter for the column and a number for the row. The original version (pionerred by VisiCalc long ago) uses RxCy to identify Row X and Column Y. So B5 in the new (and most commonly used) notation is the same as R5C3 in the old style.

Look up "Address" in Excel help for more info
 
Upvote 0

Forum statistics

Threads
1,206,949
Messages
6,075,811
Members
446,158
Latest member
octagonalowl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top