Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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
0
alisonthom
Asked:
alisonthom
  • 2
1 Solution
 
Rgonzo1971Commented:
HI,

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

Regards
0
 
Saqib Husain, SyedEngineerCommented:
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

0
 
Rgonzo1971Commented:
Hi,

You could also use

result = Selection Like "*#"

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

The other response is also most appreciated.

Thanks
Alison
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now