Re: Find PivotTable Name and set as PivotTable variable in VBA
You don't understand the concept of the 'Index' property. Every object, whether a Worksheet, Workbook, Chart or Pivot Table has an index property- and for any particular type of object, the index will start at 1 and continue the sequence for other objects of the same type. Index 1 will be the first object of that type created in that context.
It doesn't matter what the name of the pivot table is - the first pivot will have an Index of 1, so
Set pvt = ActiveSheet.PivotTables(1)
will always set a reference to the first PT, even if it's Name is 'PivotTableWastingSpaceInTheWorksheet 99"
Of course, if there's more than one Pivot Table on a sheet and you don't know the name of the one you want or any other identifying feature like the number of columns, a unique Row/column label, Heading etc, then the technical term for that is "You're Stuffed".
Another property, Count, can be queried to find out how many objects of a particular type exist...
If ActiveSheet.PivotTables.Count <> 1 Then
MsgBox "Dunno wat 2 du", vbShreik