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 ?
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" <hurriance.29zrrb_1151295602.5572@excelforum-nospam.com> wrote
in message news:hurriance.29zrrb_1151295602.5572@excelforum-nospam.com...
>
> 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
>
doesn't that code work as you want?
--
HTH
Bob Phillips
(replace somewhere in email address with gmail if mailing direct)
"hurriance" <hurriance.29zrrb_1151295602.5572@excelforum-nospam.com> wrote
in message news:hurriance.29zrrb_1151295602.5572@excelforum-nospam.com...
>
> 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
>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks