Solved

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

Posted on 2012-12-28
4
278 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 49

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 49

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA User Form Help 21 29
Copying from excel I am getting extra text 11 42
Formula Help 3 22
Problem to file 5 15
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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 Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

772 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