+ Reply to Thread
Results 1 to 4 of 4

String not working as expected

  1. #1
    Registered User
    Join Date
    09-18-2009
    Location
    Auckland NZL
    MS-Off Ver
    Excel / Access / Word 2007
    Posts
    4

    String not working as expected

    Excel 2007
    I have a VBA procedure for checking a selection (Country) to determine an action.
    Under Option Explicit I have declared Public strCountry as String.
    As part of the procedure I am asking "If strCountry is XYZ Then Do this (etc). If not do something else.
    For some reason within the procedure I am able to identify the user section, but unable to use it in a call to action.
    For example, under a Public Function:
    In the subject worksheet the user has selected "Australia" (without the quotes.)

    strCountry = Worksheets("1-REVENUES").Range("lstCountry").Value
    Msgbox strCountry '[returns "Australia" (without the quotes)]
    MsgBox Worksheets("1-REVENUES").Range("lstCountry").Value '[returns "Australia" (without the quotes)]
    MsgBox strCountry = Worksheets("1-REVENUES").Range("lstCountry").Value '[returns FALSE] ??

    The following (paraphrased)
    If strCountry = "Australia" Then
    [Do This]
    End If
    [Do something else]

    results in [Do something else].

    Why is the call not recognising the string "Australia"?? (or any other string for that matter)

    Any help appreciated.
    Last edited by WilyOne; 11-21-2011 at 08:49 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: String not working as expected

    Hi,

    It would probably help to see a sample workbook that demonstrates this problem.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: String not working as expected

    If this is not a typo:

    I
    Please Login or Register  to view this content.
    It will ALWAYS do something else because it's not inside the "If...End If"

    Please Login or Register  to view this content.
    I don't see anything wrong that would produce "False". I would conclude that you typed something wrong, but I would have to see the workbook to be sure.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  4. #4
    Registered User
    Join Date
    09-18-2009
    Location
    Auckland NZL
    MS-Off Ver
    Excel / Access / Word 2007
    Posts
    4

    Solved: String not working as expected

    Thanks for the responses.
    I have resolved the issue.
    I omitted to include an Option Compare statement (Text) at the beginning of the module.
    That seems to have fixed the problem.
    Last edited by WilyOne; 11-21-2011 at 08:47 AM. Reason: Header Correction

+ 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