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

alisonthom
alisonthom used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
HI,

result = right(myString, 1) Like "#"

Regards
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

Top Expert 2016

Commented:
Hi,

You could also use

result = Selection Like "*#"

Regards

Author

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

The other response is also most appreciated.

Thanks
Alison

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial