+ Reply to Thread
Results 1 to 16 of 16

String Comparison Not Working

  1. #1
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    String Comparison Not Working

    This should be as simple as can be, but for some reason it's not working and I can't figure out why:

    I have a string called LastSWApplication. I have a test like the following against it:

    Please Login or Register  to view this content.
    I've put it under testing and LastSWApplication is clearly equal to "Microsoft Office 2007 Professional", no ending spaces or the like, and the length is 34 characters.
    It never matches. I backed up under testing with breakpoints and if I change the check to just before the number 2 it works fine and sets ImportantApplication to Y. The check would then look like this:

    Please Login or Register  to view this content.
    If I simply add the 2 back on both sides of the equation it doesn't match.
    I have other checks like the following and they fail too:

    Please Login or Register  to view this content.
    As crazy as this sounds, it's almost as if "Microsoft Office numeric" is some special type of text. I've never had something like this in VBA but maybe I'm missing something easy. Any ideas?
    Last edited by js0873; 02-01-2017 at 02:29 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: String Comparison Not Working

    Hi js0873,

    Please use code tags when posting code.

    In theory it makes no sense... but what type of variable is LastSWApplication? How is it's value assigned?
    I assigned the string the value and performed the test, which matches.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: String Comparison Not Working

    Have you tried

    Please Login or Register  to view this content.
    Otherwise I suggest you upload the workbook so that we can check in context.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    Re: String Comparison Not Working

    LastSWApplication is a public variable used in my subroutine, assigned like this:

    Please Login or Register  to view this content.
    The data comes from an array, which is basically just loaded from a large worksheet. It grabs the 3rd row in the array:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    Re: String Comparison Not Working

    Quote Originally Posted by Richard Buttrey View Post
    Have you tried

    Please Login or Register  to view this content.
    Otherwise I suggest you upload the workbook so that we can check in context.
    That didn't work either. There's some private information in the workbook that I'd have to clean out before uploading, but let me see if other ideas surface first.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: String Comparison Not Working

    I assume you have checked the LastWSApplication value after you assign it?

  7. #7
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    Re: String Comparison Not Working

    Quote Originally Posted by Arkadi View Post
    I assume you have checked the LastWSApplication value after you assign it?
    Correct. I set a breakpoint at my comparison check and checked it then too.

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: String Comparison Not Working

    Then I have no logical explanation, as Richard said, maybe with the (cleansed) workbook we can do more.

  9. #9
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    Re: String Comparison Not Working

    OK, I'm including a cleansed worksheet. The object is to show only important software applications on a sheet called "Software Important". To get there the ImportantApplication switch needs to be set to "Y", and those checks are at the bottom.
    This should be so easy but for the life of me I can't figure out why it doesn't work. I'm sure it's something stupid. Any help is appreciated.

    I've never linked a workbook here but I think this should work.

    https://www.sugarsync.com/pf/D6471483_07272682_6720946

  10. #10
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: String Comparison Not Working

    The test in the OP is case sensitive. Is that a possible source for the error?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: String Comparison Not Working

    Your code checks for:
    "Microsoft Office 2007 Professional"
    your worksheet data does not contain this... it flips the "Professional" and "2007":
    "Microsoft Office Professional 2007"
    That is row 7 of the Installed Applications sheet, column C. Column A contains a match, but your checking is based on C, not A.
    Thus there is no match.
    Last edited by Arkadi; 02-02-2017 at 09:17 AM.

  12. #12
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    Re: String Comparison Not Working

    Quote Originally Posted by Arkadi View Post
    Your code checks for:
    "Microsoft Office 2007 Professional"
    your worksheet data does not contain this... it flips the "Professional" and "2007":
    "Microsoft Office Professional 2007"
    That is row 7 of the Installed Applications sheet, column C. Column A contains a match, but your checking is based on C, not A.
    Thus there is no match.
    Thx. I knew it had to be a stupid operator error. I had copied and pasted from column A and looked at column C and didn't see any difference. Even when I had breakpoints applied and looked at the variable I couldn't see the difference, but I just wasn't looking right, obviously. Thx so much.

  13. #13
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    Re: String Comparison Not Working

    How do I mark this as answered?

  14. #14
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: String Comparison Not Working

    Near the top on the right, there is an item called "Thread Tools", it should have an option "Mark as Solved"

    Hopefully that means your issue is resolved?

    Judging by the fact that you were kind enough to give rep points, I assume so. Thanks for that

  15. #15
    Forum Contributor
    Join Date
    05-13-2010
    Location
    Dallas, TX
    MS-Off Ver
    2019
    Posts
    129

    Re: String Comparison Not Working

    Done. Thx again.

  16. #16
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: String Comparison Not Working

    My pleasure! Sorry my last post was a bit stupid... missed your previous post...

+ 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. [SOLVED] First time String comparison using Like not working
    By capson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2016, 02:00 PM
  2. [SOLVED] String Logic Comparison not working
    By Asepic in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-16-2015, 04:55 PM
  3. String Comparison
    By tactical in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2011, 01:15 PM
  4. Larger than ">" comparison not working when used with a string
    By sungsam in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2009, 03:33 AM
  5. String comparison
    By HurricaneDan in forum Excel General
    Replies: 4
    Last Post: 11-08-2006, 02:05 PM
  6. comparison string VBA excell
    By stats in forum Excel General
    Replies: 5
    Last Post: 03-16-2006, 06:15 PM
  7. String Comparison
    By Purnima in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-08-2005, 08:06 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