I need to select a cell one row before the lastrow. How do i do that?
I have tried lastrow = lastrow -1
and it apparently doesn’t work that way.
Set pt = .PivotTables("PivotTable2")
lastrow = .Range(Split(pt.TableRange1.Address(0, 0), ":")(1)).Row
I just need to select the cell one row before the last row in column F
This will do the Job:
Set pt = .PivotTables("PivotTable2")
Dim lstr() As String
lstr = Split(pt.RowRange.Address, ":")
.Range(lstr(1)).Offset(-1, 0).Select
pt.RowRange
gives you the rows on which the Pivot Table pt
exists.
Answer:
You can Offset
the first row of the PivotTable.TableRange
to get its last row:
lastrow = pt.TableRange1.Rows(1).Offset(pt.TableRange1.Rows.Count - 1).Row
ActiveSheet.Cells(lastrow - 1, "F").Select
Tags: excelexcel, select