Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Aug 2001
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting the first Character of a String (2000)

    Thanks for your help on my Range() dilemma. Now a (hopefully) easy question:

    How do I truncate a string to get only the first character?

    For example, I want the string

    1. John Doe

    to become

    1

  2. #2
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Long Beach, California, USA
    Posts
    233
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the first Character of a String (2000)

    enter the following formula in the desired cell.
    =LEFT(A1,1)

    A1 is the cell with the data you would like to hack and 1 being the character to leave intact.


    or with VBA you could try Range("A1") .Formula ="=LEFT(Cell,1)"

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Getting the first Character of a String (2000)

    If your string is in A1, then =Left(A1,1) should work.

    In VBA you can use a similar construct with Left(strExpression,1) where strExpression is the string you wnat to work with.

    Andrew C

  4. #4
    Lounger
    Join Date
    Aug 2001
    Location
    Shropshire, UK
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the first Character of a String (2000)

    The cell formula is =left(string,num_of_characters) to return a string starting from the left.
    e.g. LEFT("Hello world",1) returns "H"
    LEFT("Hello world",3) returns "Hel"
    If num_of_characters is omitted it is assumed to be 1.

    The VBA formula is the same but if the number is omitted you get a zero length string, ""

    Ewan.

Posting Permissions

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