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
Microsoft Excel

Avatar of undefined
Last Comment
alisonthom

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rgonzo1971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Saqib Husain

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

Rgonzo1971

Hi,

You could also use

result = Selection Like "*#"

Regards
alisonthom

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

The other response is also most appreciated.

Thanks
Alison
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck