Link to home
Start Free TrialLog in
Avatar of alisonthom
alisonthom

asked on

Excel VBA - how to test if last character in a cell is a number

Hi,

I would be very grateful if you could suggest how I can use VBA to ascertain if the last character in a cell is a number (0 through to 9).

Many thanks in advance
Alison
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Select the cell and run this macro

Sub testlastnum()
If Right(Selection, 1) <= "9" And Right(Selection, 1) >= "0" Then MsgBox "yes" Else MsgBox "no"
End Sub

Open in new window

Avatar of Rgonzo1971
Rgonzo1971

Hi,

You could also use

result = Selection Like "*#"

Regards
Avatar of alisonthom

ASKER

Thank you so much for the quick and very helpful answer.

The other response is also most appreciated.

Thanks
Alison