+ Reply to Thread
Results 1 to 6 of 6

Compare Strings

  1. #1
    Registered User
    Join Date
    05-23-2017
    Location
    São Paulo, Brazil
    MS-Off Ver
    MS Office 2013
    Posts
    12

    Compare Strings

    Hi Guys,

    I`m having a problem comparing two strings in VBA, I`m used to compare using languages like C, where i can iterate trough each string as string[i].
    But in VBA, it cannot be done like that, so I tried using Mid function, but it doenst allow me to use a variable as parameter, so... how can I achieve my goal?

    Please Login or Register  to view this content.
    Last edited by Keytnknd; 05-26-2017 at 09:57 AM.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Compare Strings

    What is the issue you have, your code looks nice
    Perhaps send a sample of you data
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    05-23-2017
    Location
    São Paulo, Brazil
    MS-Off Ver
    MS Office 2013
    Posts
    12

    Re: Compare Strings

    the problem is :
    Run time error 5
    invalid procedure call or argument

    In the line
    If Mid(str1, i, 1) <> "*" Then

    I`m trying to compare for example app*e and apple , it should give me that they are equal, cause i m not counting the character *
    Last edited by Keytnknd; 05-26-2017 at 11:09 AM.

  4. #4
    Registered User
    Join Date
    05-23-2017
    Location
    São Paulo, Brazil
    MS-Off Ver
    MS Office 2013
    Posts
    12

    Re: Compare Strings

    I found the error, the For loop was starting from Index 0, but Mid needs to start from 1

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Compare Strings

    Easy, just ask ... (;-))

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Compare Strings

    Just for info - if you're happier to work with arrays like in C, you can stuff a string into an array in 1 call... (OK - so this is a whole sub, but the 'Split(strConv(...' line is the heart of it).
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 05-30-2015, 11:45 AM
  2. Compare two strings
    By voicetec in forum Excel General
    Replies: 19
    Last Post: 06-17-2014, 08:58 AM
  3. Compare Differences between 2 strings
    By wadafruck in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 12-11-2012, 07:09 PM
  4. Compare two strings
    By matrex in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-15-2012, 06:28 PM
  5. [SOLVED] Compare Strings Question
    By Sabo, Eric in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-23-2006, 11:20 PM
  6. Compare data strings?
    By Ed in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2005, 09:40 AM
  7. Compare the strings
    By yangyh in forum Excel General
    Replies: 3
    Last Post: 09-08-2005, 12:05 AM

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