Capture last visible row in filtered data

pliskers

Active Member
Joined
Sep 26, 2002
Messages
461
Office Version
  1. 2016
Platform
  1. Windows
I'm using the following code to capture the contents of a cell in the last row of a data table and then reference that row number to capture the "distname". The table has its header in row 11.

lastrow = Range("F" & Rows.Count).End(xlUp).Row
distname = Range("F" & lastrow)

Although the data is filtered, the code is capturing the last row in the entire table, including the filtered rows. I've searched for a simple modification to capture the last VISIBLE, FILTERED row but no luck so far.

Any help would be greatly appreciated!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
VBA Code:
   Dim Sp As Variant
   With ActiveSheet.ListObjects(1)
      Sp = Split(.Range.SpecialCells(xlVisible).Address, "$")
      LastRow = Sp(UBound(Sp))
   End With
 
Upvote 0
Brilliant! Thanks, that does it. I've tried SO many other snippets of code. Thanks, mate!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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