Finding last used row in a name range and to ignore data below the named ranged

Shananarocks

New Member
Joined
Jan 3, 2022
Messages
3
Office Version
  1. 2010
Platform
  1. Windows
Hi, I am quite a newbie to MS Excel VBA although I can code quite well in MS Access.
Basically in Excel, I have a named range "NameAge" (A10:B20). I need to find the row that "Joe" resides.
However, most VBA codes will either result in giving me the last row which is row 20 of the named range or row 23 where "Charles" is.
Appreciate any help.
Thanks!
 

Attachments

  • Excel_Find_LastUsedRow_NamedRange.JPG
    Excel_Find_LastUsedRow_NamedRange.JPG
    48.1 KB · Views: 9

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi & welcome to MrExcel.
How about
VBA Code:
Range("NamedAge").Find("*", , , , xlByRows, xlPrevious, False, , False).Row
 
Upvote 0
Solution
Hi & welcome to MrExcel.
How about
VBA Code:
Range("NamedAge").Find("*", , , , xlByRows, xlPrevious, False, , False).Row
Thanks for the prompt reply but I got an error message "Run-time error "1004" , Method 'Range of object'_Worsheet' failed".
Using Cells.find I was only able to find the position of "Charles" at row 23.

Set sht = ActiveSheet
LastRow = sht.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
Debug.Print "Last found used row: " & LastRow

Dim LastRow_Find As Long
LastRow_Find = sht.Range("NamedAge").Find("*", , , , xlByRows, xlPrevious, False, , False).Row
Debug.Print "LastRow_Find: " & LastRow_Find
 
Upvote 0
Is the named range on the active sheet when you run that code?
 
Upvote 0
Is the named range on the active sheet when you run that code?
LOL!!! It should be "NameAge" instead of "NamedAge". My apologies. Thanks for the instant solution. May you have the best new year and lots of good wishes too. !!!!
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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