Find The Last Row In A Range Holding A Number

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Can anyone be able to share a VBA solution to find the last cell in a range that contains a number. Seems pretty simple, I may be having brain fog and I can't see the obvious.
The range is A13:A74.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Do some of the cells in the range contain anything other than numbers? an example would clarify your question
 
Upvote 0
@Ark68 Does the below help?

VBA Code:
Sub LastNumCell()

For r = 74 To 14 Step -1
    If Not Cells(r, 1) = "" And IsNumeric(Cells(r, 1)) Then Exit For
Next

LstRow = Cells(r, 1).Row
LstAddress = Cells(r, 1).Address
MsgBox LstRow & "    " & LstAddress & "   " & Cells(r, 1).Value
End Sub
 
Upvote 1
Hi Kerryx,
Do some of the cells in the range contain anything other than numbers?
I suppose they do.
In this example, the value I'd be looking for is 72 (last row in the range with a value in it.
WS 28-May-23.xlsx
A
12
1345074001
1445074003
1545074004
1645074030
1745074031
1845074026
1945074027
2045074028
2145074006
2245074003-1
2345074004-1
2445074026-1
2545074027-1
2645074003-2
2745074004-2
2845074026-2
2945074027-2
3045074028-2
3145074030-1
3245074031-1
3345074003-3
3445074004-3
3545074030-2
3645074031-2
3745074015
3845074016
3945074003-4
4045074004-4
4145074026-3
4245074028-2
4345074030-3
4445074031-3
4545074008
4645074036
4745074017
48
4945074009
5045074010
5145074026
5245074027
5345074028
5445074022
5545074005
5645074029
5745074007
5845074021
5945074023
6045074024
6145074025
62
6345074011
6445074012
6545074013
6645074014
67
6845074033
6945074034
7045074035
7145074002
7245074032
73
74
Master_WRK
 
Upvote 0
Hi Snakehips,
I posted a reply to Kerryx just as you had posted :)
@Ark68 Does the below help?
It's on the right track. The isnumeric function won't work as we can see that the values could be text (including the last one) ... ########-t
 
Upvote 0
last cell in a range that contains a number

I'd be looking for is 72 (last row in the range with a value in it.
Those two things are not the same.
Assuming it is the second one that you want, try ..

VBA Code:
Sub FindLastRowWithValue()
  MsgBox Range("A13:A74").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End Sub
 
Upvote 0
Solution
Hi Peter ... yes, I acknowledged in my response to Kerryx that the values may not always just contain numbers, and to snakehips recognized that because of that isnumeric won't work, so changed my need to "value" from "a number". Thank you for reminding me I recognized my initial short coming.

This is the solution.
 
Upvote 0
Glad it worked for you. Thanks for the confirmation.
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,216
Members
449,215
Latest member
texmansru47

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