variable last cell in pivot table macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to make the end of my pivot table range the last cell in the
worksheet (actually the next to last cell but I can't get to the last cell
yet). Anyone know the syntax for ths? Here's my current failed experiment,
substituting a range for the hard coded R1C1:R2000C41:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'Cost Data'!Range(Selection,
ActiveCell.SpecialCells(xlLastCell))").CreatePivotTable TableDestination:="",
_

TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields("PLINE")
.Orientation = xlRowField
.Position = 1
End With

Any thoughts are welcome.
 
dim mySource as range
with worksheets("cost data")
set mysource = .range("A1:E" & .cells(.rows.count,"A").row)
end with

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:= mysource.address(external:=true)).createPivotTable _
TableDestination:="".....

I used column A to find the last row and went to column E. Change that to what
you need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top