Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-12-28
4
Medium Priority
?
311 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
[X]
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
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 700 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 52

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

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…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

722 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