So I'm brand new to VBA and having a hard time figuring out how to use a macro to update the source data on an existing pivot table.
I have data in columns A:AX, AX contains dates and I have the macro sort them leaving the blanks on bottom. I want the macro to select the source data from A1 to the last row containing data in AX. I want to do this without deleting the rows containing blank AX cells.
This is what I have so far. No clue if I'm close or completely wrong.
Dim DSheet As Worksheet
Dim PRange As Range
Dim LastRow As Long
Dim LastCol As Long
Set DSheet = Worksheets("Tool NCRs")
LastRow = DSheet.Cells(Rows.Count, "AX").End(xlUp).Row
LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)
ActiveSheet.PivotTables("PivotTable6").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"PRange", _
Version:=xlPivotTableVersion15)
ActiveSheet.PivotTables("PivotTable6").PivotCache.Refresh
EDIT* This pivot groups by dates and it won't let me do that if there are blanks. If I use a table it still pulls in blanks and ungroups my dates
Bookmarks