Solved

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

Posted on 2012-12-28
4
292 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

679 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