Need clarification on setting Range in excel from R1c1 to range("a1") type...

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
When i record a macro it shows...
"Sheet3!R1C1:R49C7"

I want it in like Sheets("Sheet3").Range("A1:E" & lr) etc.

Code:
[FONT=Courier New]       ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _[/FONT]
[FONT=Courier New]           PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _[/FONT]
[FONT=Courier New]           "path\[budget pivot table.xls]Sheet3!R1C1:R49C7" _[/FONT]
[FONT=Courier New]           , Version:=xlPivotTableVersion10)[/FONT]

I want to pick range till last row. Please help me out here...
This must be simple but stucked...


Thanks for helping.

I tried like this...

"path\[budget pivot table.xls]Sheet3!" & Range("A1:G49") & , Version:=xlPivotTableVersion10)

but still errors...
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi,

Like this:

Code:
"path\[budget pivot table.xls]Sheet3!A1:G49", Version:=xlPivotTableVersion10)
---->
Code:
"path\[budget pivot table.xls]Sheet3!A1:G" & LastRow, Version:=xlPivotTableVersion10)
 
Upvote 0
Colin, thanks alot but it error...
"Runtime error 1004 - Unable to get the pivot table property of worksheet class"

@

PS: Source if of different workbook
Code:
[/FONT]
[FONT=Courier New]ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "E:\Personal Files\Excel Files - Brian\budget pivot table\[budget pivot table.xls]Sheet3!A1:G49", Version:=xlPivotTableVersion10)

Also tried this way
Code:
[/FONT]

[FONT=Courier New]Dim LastRow  As Long
LastRow = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "E:\Personal Files\Excel Files - Brian\budget pivot table\[budget pivot table.xls]Sheet3!A1:G" & LastRow, Version:=xlPivotTableVersion10)


Thanks again and pls make this work for me...:)

Pedie
 
Upvote 0
Pedie

Why not try sticking with the R1C1 notation?

You can still use your last row variable.
Code:
strR1C1Range = "R1C1:R" & LastRow & "C7"
 
Dim LastRow  As Long
LastRow = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "E:\Personal Files\Excel Files - Brian\budget pivot table\[budget pivot table.xls]Sheet3!" & strR1C1Range, Version:=xlPivotTableVersion10)
PS You don't need to use the string, just though it might make things a little clearer.
 
Upvote 0
Hi,

The error description suggests to me that the activesheet did not have a pivot table called PivotTable1 when you ran the code...
 
Upvote 0
Norie, thanks i tried that too but errors..
Colin thanks again..! you are right the pivot name was incorrect, my bad...

but it still error...
I tried this way,...
Sheets("Sheet3") is of different workbook, do i have to make vba first open the workbook for this?

it is saying i need at least 2 rows of data...
runtime error..(2140724809 - 80070057...)


Code:
[/FONT]
[FONT=Courier New]Dim LastRow  As Long
LastRow = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.PivotTables("Pivot_ped1").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "E:\Personal Files\Excel Files - Brian\budget pivot table\[budget pivot table.xls]Sheet3!A1:G" & LastRow, Version:=xlPivotTableVersion10)
End Sub

if i use rows.count instead of LastRow it picks up till 60000 rows...including blanks which i do not want to...


Thanks again
 
Upvote 0
When the error occurs, what value does LastRow hold?

It looks a little strange that you are calculating the last row from one sheet and then applying it to another.

As a test, you could set LastRow to 10 to see if the error persists?
 
Upvote 0
It is taking sheet3 in thiswork and not the one in workbook called "budget pivot table.xls"

What should i do now so that it take different book sheet3 for lastrow?
Sorry for wasting your time but thanks alot...:)
 
Upvote 0
You're not wasting my time - this is exactly what the forum is for!

I can help you with that but I need to know a couple of things:

(1) What is the name of the worksheet the pivot table "Pivot_Ped1" sits in?
(2) Is the "budget pivot table.xls" workbook open in the same Excel instance when the code is run?
 
Upvote 0
You're not wasting my time - this is exactly what the forum is for!


Thanks again!!!:)

budget pivot table.xls is not opened...
sheet3 is in budget pivot table.xls which is Source for my pivot.
Pivot_Ped1 sits in "Sheet1" of "Book1.xls"
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,472
Members
452,915
Latest member
hannnahheileen

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