+ Reply to Thread
Results 1 to 6 of 6

# of letters in a string

  1. #1
    Registered User
    Join Date
    04-25-2005
    Posts
    99

    # of letters in a string

    Is there anyway to tell how many letters are in a string? More specifically, I have a userform where the user enters a string into a textbox. The textbox will only accept a total of 10 letters. When the string variable gets passed to my sub routine, I need to know how many letters are in that string.

    If I can determine how many letters are in the string, if there are less than 10, I then want to add spaces to the end of that string to make it 10 characters long.

    For example, if I enter:
    "August" (6 characters) - it will then change it to "August____" (_ = " ")
    "California" (10 characters) - it will not add any spaces


    TIA for any help,

    DejaVu

  2. #2
    Tom Ogilvy
    Guest

    Re: # of letters in a string

    sStr = Left(sStr & " ",10)

    --
    Regards,
    Tom Ogilvy


    "DejaVu" <DejaVu.1tazaf_1123265141.1859@excelforum-nospam.com> wrote in
    message news:DejaVu.1tazaf_1123265141.1859@excelforum-nospam.com...
    >
    > Is there anyway to tell how many letters are in a string? More
    > specifically, I have a userform where the user enters a string into a
    > textbox. The textbox will only accept a total of 10 letters. When the
    > string variable gets passed to my sub routine, I need to know how many
    > letters are in that string.
    >
    > If I can determine how many letters are in the string, if there are
    > less than 10, I then want to add spaces to the end of that string to
    > make it 10 characters long.
    >
    > For example, if I enter:
    > "August" (6 characters) - it will then change it to "August____" (_ =
    > " ")
    > "California" (10 characters) - it will not add any spaces
    >
    >
    > TIA for any help,
    >
    > DejaVu
    >
    >
    > --
    > DejaVu
    > ------------------------------------------------------------------------
    > DejaVu's Profile:

    http://www.excelforum.com/member.php...o&userid=22629
    > View this thread: http://www.excelforum.com/showthread...hreadid=393382
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: # of letters in a string

    msgbox len(sStr) gives the number of characters in the string held in
    variable sStr (just for completeness)

    --
    Regards,
    Tom Ogilvy

    "DejaVu" <DejaVu.1tazaf_1123265141.1859@excelforum-nospam.com> wrote in
    message news:DejaVu.1tazaf_1123265141.1859@excelforum-nospam.com...
    >
    > Is there anyway to tell how many letters are in a string? More
    > specifically, I have a userform where the user enters a string into a
    > textbox. The textbox will only accept a total of 10 letters. When the
    > string variable gets passed to my sub routine, I need to know how many
    > letters are in that string.
    >
    > If I can determine how many letters are in the string, if there are
    > less than 10, I then want to add spaces to the end of that string to
    > make it 10 characters long.
    >
    > For example, if I enter:
    > "August" (6 characters) - it will then change it to "August____" (_ =
    > " ")
    > "California" (10 characters) - it will not add any spaces
    >
    >
    > TIA for any help,
    >
    > DejaVu
    >
    >
    > --
    > DejaVu
    > ------------------------------------------------------------------------
    > DejaVu's Profile:

    http://www.excelforum.com/member.php...o&userid=22629
    > View this thread: http://www.excelforum.com/showthread...hreadid=393382
    >




  4. #4
    Stefan Hojnowski
    Guest

    Re: # of letters in a string

    Or you could do the following:

    sStr = sStr & Space(10 - Len(sStr))

    "Tom Ogilvy" wrote:

    > sStr = Left(sStr & " ",10)
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "DejaVu" <DejaVu.1tazaf_1123265141.1859@excelforum-nospam.com> wrote in
    > message news:DejaVu.1tazaf_1123265141.1859@excelforum-nospam.com...
    > >
    > > Is there anyway to tell how many letters are in a string? More
    > > specifically, I have a userform where the user enters a string into a
    > > textbox. The textbox will only accept a total of 10 letters. When the
    > > string variable gets passed to my sub routine, I need to know how many
    > > letters are in that string.
    > >
    > > If I can determine how many letters are in the string, if there are
    > > less than 10, I then want to add spaces to the end of that string to
    > > make it 10 characters long.
    > >
    > > For example, if I enter:
    > > "August" (6 characters) - it will then change it to "August____" (_ =
    > > " ")
    > > "California" (10 characters) - it will not add any spaces
    > >
    > >
    > > TIA for any help,
    > >
    > > DejaVu
    > >
    > >
    > > --
    > > DejaVu
    > > ------------------------------------------------------------------------
    > > DejaVu's Profile:

    > http://www.excelforum.com/member.php...o&userid=22629
    > > View this thread: http://www.excelforum.com/showthread...hreadid=393382
    > >

    >
    >
    >


  5. #5
    Registered User
    Join Date
    04-25-2005
    Posts
    99
    Thanks to both of you... your help is much appreciated.

    DejaVu

  6. #6
    Registered User
    Join Date
    05-15-2008
    Posts
    13

    # of letters in a string

    Str = Len(string)

    Syntax LEN will provide the actual number of characters within a string
    Example # = len(activecell)

+ 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