+ Reply to Thread
Results 1 to 3 of 3

Compare string with integer

  1. #1
    Registered User
    Join Date
    01-27-2006
    Posts
    15

    Compare string with integer

    I am using excel 2002. I want to compare a string variable with an integer variable. i.e.

    dim i as integer
    i=1
    dim s as string
    s="1"
    if i = s then
    ...........
    else
    ......
    end if

    however, when I run this macro, a error occur.
    how should I compare the variable with two different format ?

  2. #2
    NickHK
    Guest

    Re: Compare string with integer

    You have to "coerce" the data in one type to that of the other. Look up
    "coerce" in VBA Help for the various Cxxx function.

    NickHK

    "hurriance" <[email protected]> wrote
    in message news:[email protected]...
    >
    > I am using excel 2002. I want to compare a string variable with an
    > integer variable. i.e.
    >
    > dim i as integer
    > i=1
    > dim s as string
    > s="1"
    > if i = s then
    > ..........
    > else
    > .....
    > end if
    >
    > however, when I run this macro, a error occur.
    > how should I compare the variable with two different format ?
    >
    >
    > --
    > hurriance
    > ------------------------------------------------------------------------
    > hurriance's Profile:

    http://www.excelforum.com/member.php...o&userid=30882
    > View this thread: http://www.excelforum.com/showthread...hreadid=555450
    >




  3. #3
    Bob Phillips
    Guest

    Re: Compare string with integer

    doesn't that code work as you want?

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "hurriance" <[email protected]> wrote
    in message news:[email protected]...
    >
    > I am using excel 2002. I want to compare a string variable with an
    > integer variable. i.e.
    >
    > dim i as integer
    > i=1
    > dim s as string
    > s="1"
    > if i = s then
    > ..........
    > else
    > .....
    > end if
    >
    > however, when I run this macro, a error occur.
    > how should I compare the variable with two different format ?
    >
    >
    > --
    > hurriance
    > ------------------------------------------------------------------------
    > hurriance's Profile:

    http://www.excelforum.com/member.php...o&userid=30882
    > View this thread: http://www.excelforum.com/showthread...hreadid=555450
    >




+ 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