Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenating a string and an integer [email protected] Excel Programming 2 April 5th 06 07:40 PM
Concatenate two variables (String & Integer) Sreenivas Varadhan Excel Programming 3 December 12th 05 01:28 PM
ListBox2.AddItem ListBox1.Value becomes a String when being Integer? SIGE Excel Programming 2 March 30th 05 04:26 PM
Declaring variables (Long, String, Integer) and interpretation spe MrT Excel Programming 4 December 12th 04 12:43 PM
Is there a function to convert a string representing an integer i. perin Excel Programming 1 October 6th 04 09:36 PM


All times are GMT +1. The time now is 03:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"