Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Number Format

I have variable that is declared as Long. When I use the
variable in an If statement such as
"If cells(r,c)=variable then"
I get the cell as a number but the variable insists on
appearing in quotes, indicating a string. As a result
the If statement comes out false.

Example If 2501 = "2501" then is false
How can I ensure that the variable is represented as a
number in the if statement so that thje answer is True?

Lionel

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Number Format

Hi
try something like
IF CLng(cells(r,c).value)=variable then

--
Regards
Frank Kabel
Frankfurt, Germany


Lionel Fridjhon wrote:
I have variable that is declared as Long. When I use the
variable in an If statement such as
"If cells(r,c)=variable then"
I get the cell as a number but the variable insists on
appearing in quotes, indicating a string. As a result
the If statement comes out false.

Example If 2501 = "2501" then is false
How can I ensure that the variable is represented as a
number in the if statement so that thje answer is True?

Lionel

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Number Format

Can you post your code? A Long would never appear as a String. There must be
some confusion in the code that you have missed.

You could coerce the String to a Long using CLng but that really should not
be necessary with the proper declaration.

--

Vasant


"Lionel Fridjhon" wrote in message
...
I have variable that is declared as Long. When I use the
variable in an If statement such as
"If cells(r,c)=variable then"
I get the cell as a number but the variable insists on
appearing in quotes, indicating a string. As a result
the If statement comes out false.

Example If 2501 = "2501" then is false
How can I ensure that the variable is represented as a
number in the if statement so that thje answer is True?

Lionel



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Number Format

When you say the variable appears in quotes, where are you seeing it in
quotes?

try this before the if statement

msgbox cells(r,c).Value & "<--" & variable & " " & cells(r,c).value =
variable

--
Regards,
Tom Ogilvy


"Lionel Fridjhon" wrote in message
...
I have variable that is declared as Long. When I use the
variable in an If statement such as
"If cells(r,c)=variable then"
I get the cell as a number but the variable insists on
appearing in quotes, indicating a string. As a result
the If statement comes out false.

Example If 2501 = "2501" then is false
How can I ensure that the variable is represented as a
number in the if statement so that thje answer is True?

Lionel



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
Excel is defaulting to Number format instead of General format Kim Excel Discussion (Misc queries) 1 March 11th 10 01:25 PM
Replace million-billion number format to lakhs-crores format Sumit Excel Discussion (Misc queries) 1 December 9th 05 04:58 PM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM
convert text-format number to number in excel 2000%3f Larry Excel Discussion (Misc queries) 1 July 29th 05 08:18 PM
excel format cells/Number/Category: Number problem Matts Excel Discussion (Misc queries) 5 December 9th 04 09:47 PM


All times are GMT +1. The time now is 05:10 AM.

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

About Us

"It's about Microsoft Excel"