I’m getting back into VBA after several years away. Refreshing my memory is harder than I thought. I’m creating multiple pivot tables from the same data sheet (“SOW Detail”), and inserting them one after another on “Sheet2”, with 3 empty rows between them. The macro recorder is not capturing the steps to find the last filled cell and come down 4 rows. It’s only capturing the result as the location for the new table—e.g., “Sheet2!R78C1” in the code below. To determine that cell, I’m selecting AA1, and doing the following sequence, then moving down 4 rows, to leave 3 blank rows between tables. How can I incorporate the "Selection.End(xl..." steps and moving down 4 rows into the code to create the pivot tables? Note, the number of rows in each table can vary.
Code to find last filled cell:
Rich (BB code):
Selection.End(xlDown).Select
Selection.End(xlToLeft).Select
Selection.End(xlUp).Select
Code to create pivot table:
Rich (BB code):
Sheets("SOW Detail").Select
ActiveWorkbook.Worksheets("Sheet2").PivotTables("PivotTable3").PivotCache._
CreatePivotTableTableDestination:="Sheet2!R78C1", TableName:="PivotTable4"_
, DefaultVersion:=xlPivotTableVersion15
Sheets("Sheet2").Select
Cells(78, 1).Select
WithActiveSheet.PivotTables("PivotTable4").PivotFields("Location")
.Orientation = xlRowField
.Position = 1
End With
WithActiveSheet.PivotTables("PivotTable4").PivotFields("Location")
.Orientation = xlPageField
.Position = 1
End With
WithActiveSheet.PivotTables("PivotTable4").PivotFields("RoomType")
.Orientation = xlRowField
.Position = 1
End With
WithActiveSheet.PivotTables("PivotTable4").PivotFields("RoomType")
.Orientation = xlColumnField
.Position = 1
End With
WithActiveSheet.PivotTables("PivotTable4").PivotFields("SolutionFamily2")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable4").AddDataFieldActiveSheet.PivotTables( _
"PivotTable4").PivotFields("Qty2"), "Sum ofQty2", xlSum
Thank you so much!