+ Reply to Thread
Results 1 to 4 of 4

partially comparing strings vba

  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    partially comparing strings vba

    Hello I'm trying to get user input from a textbox and then see if the sequence of numbers are in the array. I tried a like but it doesn't seem to work my code is below.

    thanks,
    JO

    For example :
    user input = 2409
    the array returns = 2409, 24096, 240967

    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,776

    Re: partially comparing strings vba

    Can you post all of your code? The expression above will be True if the value of J_NO is a substring of InfoArray(x, 0), but just in that one element. If you are trying to find out if that value appears anywhere in the array, you need a loop to check every element. Does each element of InfoArray have a single digit, or a complete number that could contain J_NO?

    Also, arrays don't "return" anything so I'm not sure what your last line means.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    12-17-2012
    Location
    Buffalo, NY
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: partially comparing strings vba

    Thanks for the reply it is much appreciated. I ended up figuring it out and using the code below. By array return I meant the values being pulled from the array. My code loops through the array and then uses the code below. If there is a more efficient way to do this let me know I'm new to vba and programming in general.

    Example:
    user input: 2409
    values pulled: 24090, 24091, 24092, 24093 ...etc

    Please Login or Register  to view this content.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,776

    Re: partially comparing strings vba

    Sounds like it will work fine as long as the number you are looking for is always at the beginning of the number in the array. Your first condition works fine too, and the number can be anywhere, not just the beginning.

+ 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