+ Reply to Thread
Results 1 to 4 of 4

String Compares

  1. #1
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200

    String Compares

    My program assigns a variable one of three values - either "Lancaster", "DeSoto" or "Cedar Hill". My string compares for Lancaster and DeSoto work fine but can't get anything happening for Cedar Hill. I looked at the value of the variable and it appears to be correct. However, when I did a StrComp for the variable and the string "Cedar Hill", they did, of course, not come out as equal. What am I missing?
    Last edited by bstubbs; 01-14-2009 at 08:13 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486
    Try supplying the code........

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello bstubbs,

    As Dave mentioned, seeing your workbook would help. Here are a few common problems to look for. Sometimes leading or trailing spaces can cause this, especially if the text was entered by the user. Use the Trim function to remove any leading or trailing spaces. Case can be another problem. It is always best to use case insensitive comparisons. Check the if the macro module is explicitly setting the type of comparison with the Option Compare statement, as this will override any code settings.

    Sincerely,
    Leith Ross

  4. #4
    Forum Contributor
    Join Date
    01-09-2009
    Location
    Cedar Hill, Tx
    MS-Off Ver
    Excel 2003
    Posts
    200
    I didn't think that it was a leading or trailing space issue in that it didn't happen with two of the selections, only the third. However, I changed the code to "isdName = lTrim(rTrim(active.cell.value))" and it worked fine. Go figure. Anyway, if you hadn't mentioned that, I wouldn't have checked. I feel stupid but appreciate the input.

+ 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