+ Reply to Thread
Results 1 to 7 of 7

Looping though multiple strings

  1. #1
    Registered User
    Join Date
    12-28-2006
    Posts
    97

    Looping though multiple strings

    Is there a way to loop though a string and pull out each letter and assign it to its own variable that can be recaled using Letter1 letter2 ect?

    Please Login or Register  to view this content.

    I have gotten this to work with a message box but I want to have each letter be assigned as it's own varible or string.
    Please Login or Register  to view this content.
    Last edited by insanity66; 05-27-2010 at 10:56 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Looping though multiple strings

    Your syntax is wrong, but why can't you reference using the Mid formula?

    E.g Letter 4 = Mid(String, 4, 1)

  3. #3
    Forum Contributor
    Join Date
    02-25-2010
    Location
    Boston
    MS-Off Ver
    Excel 2007
    Posts
    174

    Re: Looping though multiple strings

    It would be easier to either

    1) have a variable that you pass to a mid function to return the letter

    2) create an array where each element holds a letter
    so an array called mystring and the string "Test String"
    mystring(0) = T
    myString(1) = e
    etc...

    And you pass a variable to mystring(x - 1) where x is the position you want.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Looping though multiple strings

    Could you not just refer to the letter directly in the array, rather than a variable?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    02-25-2010
    Location
    Boston
    MS-Off Ver
    Excel 2007
    Posts
    174

    Re: Looping though multiple strings

    You can certainly refer to it directly, i just was unsure of his needs. Maybe he wants to type in a # in a cell and pass back the correspinding letter? I dunno, was just giving him options. The best way would just stick with Mid though as stephen said.

  6. #6
    Registered User
    Join Date
    12-28-2006
    Posts
    97

    Re: Looping though multiple strings

    Quote Originally Posted by StephenR View Post
    Your syntax is wrong, but why can't you reference using the Mid formula?

    E.g Letter 4 = Mid(String, 4, 1)

    The reason I did not go that way is because the text string lenght is always going to be changing and each time the code runs there will be a diff amount of Letter1....

  7. #7
    Registered User
    Join Date
    12-28-2006
    Posts
    97

    Re: Looping though multiple strings

    Thanks to everyone
    Kyles approached worked best for me.
    I’m sorry I did not completely explain what I was doing but I did not know where to begin.
    In short I am breaking down diagnosis that have similar looking strings to make them noticeably different, to prevent misinterpretation
    Thanks Again

+ 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