How to find first row after filter

vinmam123VBA

New Member
Joined
Dec 18, 2020
Messages
33
Office Version
  1. 365
Platform
  1. Windows
Hi,

Can you please help me in finding Firstrow after applying filter?

Would like to find the row number highlighted after applying filter

1608728566031.png


Thanks,
Vin
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
How about
VBA Code:
   MsgBox Range("A2:A" & Rows.count).SpecialCells(xlVisible)(1).Row
 
Upvote 0
How about
VBA Code:
   MsgBox Range("A2:A" & Rows.count).SpecialCells(xlVisible)(1).Row
Thank for the response! It is not selecting dynamically. For example if filter changed then visible row number will also get change that time frow number should also get change

Regards,
Vinayak
 
Upvote 0
There is nothing in VBA that detects a change in the autofilter.
If you have any formulae on the sheet, you could use the calculation event, but that will trigger whenever any cell on the sheet recalculates.
Another possible option would be to use a selection change event, but that is not guaranteed to work, as you can change the filter without selecting a different cell.
 
Upvote 0
How about
VBA Code:
MsgBox Range("A2:A" & Rows.count).SpecialCells(xlVisible)(1).Row

I actually had to deal with something like this yesterday. The issue that I was having was with the wrong value being returned when the filter returned NO data (it would return the first visible blank row instead). So here is a little edit to your code that handles that:
VBA Code:
    Dim r As Long
    r = Range("A2:A" & Rows.Count).SpecialCells(xlVisible)(1).Row
    
    If Cells(r, "A") <> "" Then
        MsgBox "First row in filter is " & r
    Else
        MsgBox "No data returned by filter"
    End If
 
Upvote 0

Forum statistics

Threads
1,214,887
Messages
6,122,095
Members
449,064
Latest member
Danger_SF

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