Results 1 to 4 of 4

Returning first 3 characters of a string

This is a discussion on Returning first 3 characters of a string within the Excel Questions forums, part of the Question Forums category; I would like to get the first three characters of a string... What I have is a bunch of part ...

  1. #1
    New Member
    Join Date
    May 2003
    Posts
    6

    Default Returning first 3 characters of a string

    I would like to get the first three characters of a string...

    What I have is a bunch of part numbers starting with ST- and I am using them in a macro. There are are parts in there though and the spacing between them is inconsistant. I just have a for loop going down the spread sheet so all I need is a way to get the first three characters of a string for my If statement. Thanks.

  2. #2
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    64,588

    Default Re: Returning first 3 characters of a string

    =LEFT(A1,3)

    wher A1 contains your string

  3. #3
    New Member
    Join Date
    May 2003
    Posts
    6

    Default Re: Returning first 3 characters of a string

    Quote Originally Posted by Andrew Poulsom
    =LEFT(A1,3)

    wher A1 contains your string
    I believe that is what you would have done to display that in the spreadsheet itself.... and I don't have room for it. I would like the macro to read the string as it is from the Sheet and then take its first three characters

  4. #4
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    64,588

    Default Re: Returning first 3 characters of a string

    In code:

    x = Left(Range("A1").Value,3)

    VBA has the same function.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com