Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2012-12-28
4
284 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 50

Accepted Solution

by:
Rgonzo1971 earned 175 total points
ID: 38727110
HI,

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

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38727129
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 50

Expert Comment

by:Rgonzo1971
ID: 38727133
Hi,

You could also use

result = Selection Like "*#"

Regards
0
 

Author Closing Comment

by:alisonthom
ID: 38727232
Thank you so much for the quick and very helpful answer.

The other response is also most appreciated.

Thanks
Alison
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

792 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