R1C1 VBA Assistance PLZ

Jeff9915

New Member
Joined
Feb 8, 2005
Messages
24
I've Tried many times to get the systax correct when tring to modify R1C1 selections.

I only need to change the row count in a pivot table for adding new data. The counting is no problem getting it in my code is.

Below is the code I need to sub a variable for R11 in the example. I just cannot get the syntax right to modify it.


Range("A4").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
"Combined!R1C1:R11C9"
ActiveWorkbook.ShowPivotTableFieldList = True
ActiveWorkbook.ShowPivotTableFieldList = False
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi Jeff,

Welcome to the board.

It should be a simple matter of inserting the variable between two halves of the formula (enclosed within quotes).

Like this:
Code:
Sub TestR1C1()
    Dim lRow As Long
    
    'ActiveCell.FormulaR1C1 = "=SUM(RC[-1]:R[4]C[-1])"
    'becomes
    lRow = 4
    ActiveCell.FormulaR1C1 = "=SUM(RC[-1]:R[" & lRow & "]C[-1])"
    
End Sub
HTH
 
Upvote 0
Thanks for the info but I don't see how this works form my code above? I'm newish to VBA and cannot see the relationship. I require more details. TIA
 
Upvote 0
OK tried to use your info and changed the following but still no go. Debug error.


ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
"Combined!(RC[-1]:R[" & cnt & "]C9)"
 
Upvote 0
Hi Jeff,

Sorry for any confusion caused (I was just trying to illustrate the idea). How about :

cnt = 11
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
"Combined!R1C1:R" & cnt & "C9)"
 
Upvote 0

Forum statistics

Threads
1,203,489
Messages
6,055,724
Members
444,814
Latest member
AutomateDifficulty

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