Good day,
I'm trying to get the range to create a pivot table. The Column amounts can differ each month and the rows. My code is not working at the marked section (Bold) to set the Pivot table range and I believe the line after that won't either to create the Pivot cache. Is there a better way to do it or to fix this code, please?
Dim RowsCount As Long, ColCount As Long
Dim wsStores As Worksheet
Dim pCache As PivotCache
Dim pTable As PivotTable
Dim PvtRange As Range
Dim lastRows As Long
Set wsStores = Worksheets.Add
RowsCount = Worksheets("Active Instances").Cells(14, 1).End(xlDown).Row
ColCount = Worksheets("Active Instances").Cells(14, Columns.Count).End(xlToLeft).Column
**PvtRange = Worksheets("Active Instances").Range(RowsCount, ColCount)**
Set pCache = ActiveWorkbook.PivotCaches.Create(xlDatabase, PvtRange)
Set pTable = pCache.CreatePivotTable(wsStores.Range("A3"))
Set PvtRange = Worksheets("Active Instances").Range(RowsCount, ColCount). But even then, this code isn't going to work, as that just sets the range to a single cell, and you can't make a PivotTable out of a single cell.