Find last row in filtered range

robertvdb

New Member
Joined
Jan 10, 2021
Messages
18
Office Version
  1. 2010
Platform
  1. Windows
I have a list with cities in USA and Canada. Now I need some VBA code to identify the last row in this list (row 23 in this case), however AFTER the filter has been applied.

So if I filter the list on "USA", the result of the VBA should still be row 23, not row 18.

Can anybody help ? See the enclosed screen capture.
 

Attachments

  • cities_usa.png
    cities_usa.png
    122.7 KB · Views: 7

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,770
Office Version
  1. 365
Platform
  1. Windows
Will col A ever have blank cells?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,770
Office Version
  1. 365
Platform
  1. Windows
In that case you could use
VBA Code:
   LastRow = Application.CountA(Range("A:A"))
 

robertvdb

New Member
Joined
Jan 10, 2021
Messages
18
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

Thanks !

I have a similar case where the first row of the data is the 6th row, so the last row here would be row 27. Is there any solution for this ?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,770
Office Version
  1. 365
Platform
  1. Windows
Just add 5 to the result.
 

robertvdb

New Member
Joined
Jan 10, 2021
Messages
18
Office Version
  1. 2010
Platform
  1. Windows

ADVERTISEMENT

yes, but what if the starting row is dynamic ? Sometimes it's the 6th, sometimes it's another...
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,770
Office Version
  1. 365
Platform
  1. Windows
Then you will need to find the row of data, add that number to the result less 1
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,770
Office Version
  1. 365
Platform
  1. Windows
Ok, any problems, just shout.
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,129,987
Messages
5,639,399
Members
417,085
Latest member
Aman2626

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
Top