ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compare string with integer (https://www.excelbanter.com/excel-programming/365340-compare-string-integer.html)

hurriance[_8_]

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 ?


--
hurriance
------------------------------------------------------------------------
hurriance's Profile: http://www.excelforum.com/member.php...o&userid=30882
View this thread: http://www.excelforum.com/showthread...hreadid=555450


NickHK

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" wrote
in message ...

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




Bob Phillips

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" wrote
in message ...

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





All times are GMT +1. The time now is 06:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com