Solved

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

Posted on 2012-12-28
4
258 Views
Last Modified: 2012-12-28
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
Comment
Question by:alisonthom
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 175 total points
Comment Utility
HI,

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

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
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
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

You could also use

result = Selection Like "*#"

Regards
0
 

Author Closing Comment

by:alisonthom
Comment Utility
Thank you so much for the quick and very helpful answer.

The other response is also most appreciated.

Thanks
Alison
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now