Pivot Table - Last Row

JoeSalmi

Board Regular
Joined
Jan 31, 2011
Messages
128
How can I get VB to get me to the last row of a pivot table as soon as I open up that worksheet?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this in your worksheet module:
Code:
Private Sub Worksheet_Activate()

'Takes you to the last cell of the pivot table:
With ActiveSheet.PivotTables(1).TableRange2
    .Cells(.Cells.Count).Select
End With

End Sub
 
Upvote 0
that does work but I'm such an idiot...

What I really need is.. hahaha

I need to activate the first blank cell in column B AFTER B8.

In my case I have data in B8:B19 but B20 is blank. I want it to find the first blank cell.
 
Upvote 0
Try one of these:
Code:
'This takes you to the cell below the last cell with data (or B2 if the column is empty)
Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Select

'This takes you to the first empty cell after B8:
If Not IsEmpty(Range("B9")) Then
    Range("B8").End(xlDown).Offset(1, 0).Select
Else
    Range("B9").Select
End If
The first one finds the first blank cell from the bottom up (= usually the safest way if you're adding data to the sheet). The second one finds the first empty blank cell after B8 but doesn't make sure the rest of the cells in that row are empty.

The second one can be changed to
Code:
Range("B8:B" & Rows.Count).SpecialCells(xlCellTypeBlanks).Cells(1).Select
The difference is you don't need the IF sentence.

None of the lines checks if B8 is actually empty. The SpecialCells-solution takes you to B8 if it's empty. If you want to skip that, change the range to start from B9.
 
Upvote 0
They both work like a charm THANK YOU SO MUCH.

Using that same method I would also like to have it automatically do that along with a refresh as soon as the sheet is selected. But only do it once after the sheet is opened.

What can I add to this to make it stop looping?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    ActiveSheet.PivotTables("PivotTable6").PivotCache.REFRESH
    
    'Takes you to the first blank cell
    Range("B8:B" & Rows.Count).SpecialCells(xlCellTypeBlanks).Cells(1).Select

End Sub
 
Last edited:
Upvote 0
When working with events macros it's usually a good practice to add "Application.EnableEvents=False" to the beginning of the macro and turn the events back on at the very end of the macro.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,681
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top