+ Reply to Thread
Results 1 to 6 of 6

Check if character is a letter or a number

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Check if character is a letter or a number

    Hey all,

    I have a cell range that is passed as a String to a function, and within that function I need to extract only the Column letter. If it was just 1 letter it would be simple, but it may be 2, so does anybody know of a way of testing to see if the second character is a letter or a number?

    Thanks.
    Last edited by duckboy1981; 09-04-2009 at 05:54 AM.
    Ducks are better crispy...

  2. #2
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Re: Check if character is a letter or a number

    THis may help a little:

    Please Login or Register  to view this content.
    then just use the function Isnumber in the code if it returns true it's a number if its's false it's a string?
    Mr MaGoo
    Magoo.Inc MMVII

    If i've helped please add to my Rep by Clicking on the Blue Scales in the top right hand corner of the post

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Check if character is a letter or a number

    How are you constructing the range reference in the very first instance... ie show us the construct of the function from the native cell ?

    In general you can use IsNumeric in VBA but I would say this is going the long way around (remember in 2007 the column identifier could be 3 chars long) ... IMO you'd be better off passing either the range as an actual range to the Function or:

    Please Login or Register  to view this content.
    Out of idle curiosity - why do you need the letter in the first instance ?

  4. #4
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Check if character is a letter or a number

    It's ok, I've just had a moment! I am constructing the Range from a Letter and a Number, so I'm just gonna pass them seperatly to the function and put them together in the one instance to make the range, the rest of the time I only need the Column anyway.

    Thanks.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Check if character is a letter or a number

    In VBA you're generally far better off using R1C1 type notation in code as opposed to A1 notation, eg for B10:

    Cells(10,2)

    as opposed to

    Range("B10")

    ... the reasons are as you've just illustrated quite plain to see ie much easier to increment from column 26 to column 27 than from Z to AA etc...

  6. #6
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Check if character is a letter or a number

    Fair point, it is after all alot easier to work with numbers rather than letters. I find it odd that it is the other way around though - it would seem to make more sense if "B10" was equal to (2,10) rather than (10,2), but hey-ho, I'm no expert!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1