0

Something wrong with my pivot notation 2 line shows an error but if I put "4" instead of "lastRow" it works. What am I doing wrong?. How to change fixed range into dynamic?

Dim lastRow As Integer
Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, "Sheet1!R1C1:R10C" & "lastRow")
Set pt = pc.CreatePivotTable(Range("I2"))
salti
  • 27
  • 5
  • lastRow is ofcourse defined lastRow = Range("A" & Rows.Count).End(xlUp).Row – salti Sep 16 '16 at 10:19
  • `"Sheet1!R1C1:R10C" & "lastRow"` is the same as `"Sheet1!R1C1:R10ClastRow"`. You probally want `"Sheet1!R1C1:R10C" & lastRow` – Vincent G Sep 16 '16 at 10:31

1 Answers1

0

Remove the quote around lastrow:

Set pc = ActiveWorkbook.PivotCaches.Create(xlDatabase, "Sheet1!R1C1:R10C" & lastRow)
Vincent G
  • 3,153
  • 1
  • 13
  • 30