Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default if statement dealing with numberical numbers and text

Hi, all:

I have the folloiwng code. If cell A1 is a numberical number 0, then
a value 1 will be returned in cell B1. However, if I enter a text
string into cell A1, it will still return a number 1 in cell B1. How
to list them as two different cases, i.e. return a different value in
cell B1 if cell A1 is text string? I appreciate your help! Thank you
so much!

Sub ReturnDifferentNumber()
Range("B1") = 0

If Range("A1").Value 0 Then
Range("B1").Value = 1
End If
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default if statement dealing with numberical numbers and text

Try using something like this:

WorksheetFunction.IsNumber(Range("A1"))

Note that it returns false if the cell isempty

You may want to check
if not ISEMPTY(Range("A1")) then
IF WorksheetFunction.IsNumber(Range("A1")) and _
Range("A1").VALUE 0 then

rANGE("b1").VALUE = 1
END IF
END IF

HTH,
Barb Reinhardt


" wrote:

Hi, all:

I have the folloiwng code. If cell A1 is a numberical number 0, then
a value 1 will be returned in cell B1. However, if I enter a text
string into cell A1, it will still return a number 1 in cell B1. How
to list them as two different cases, i.e. return a different value in
cell B1 if cell A1 is text string? I appreciate your help! Thank you
so much!

Sub ReturnDifferentNumber()
Range("B1") = 0

If Range("A1").Value 0 Then
Range("B1").Value = 1
End If
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default if statement dealing with numberical numbers and text

On May 22, 5:17 pm, Barb Reinhardt
wrote:
Try using something like this:

WorksheetFunction.IsNumber(Range("A1"))

Note that it returns false if the cell isempty

You may want to check
if not ISEMPTY(Range("A1")) then
IF WorksheetFunction.IsNumber(Range("A1")) and _
Range("A1").VALUE 0 then

rANGE("b1").VALUE = 1
END IF
END IF

HTH,
Barb Reinhardt



" wrote:
Hi, all:


I have the folloiwng code. If cell A1 is a numberical number 0, then
a value 1 will be returned in cell B1. However, if I enter a text
string into cell A1, it will still return a number 1 in cell B1. How
to list them as two different cases, i.e. return a different value in
cell B1 if cell A1 is text string? I appreciate your help! Thank you
so much!


Sub ReturnDifferentNumber()
Range("B1") = 0


If Range("A1").Value 0 Then
Range("B1").Value = 1
End If
End Sub- Hide quoted text -


- Show quoted text -


Thanks, it works as desired.

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
sort in numberical order Dawn Excel Discussion (Misc queries) 4 January 3rd 07 04:06 PM
Dealing with minus numbers in formulas duubgina Excel Discussion (Misc queries) 6 May 27th 06 08:02 PM
Dealing with range of numbers in a cell Penny Excel Worksheet Functions 5 May 4th 06 08:20 PM
Dealing with numbers that begin with a 0 SueB Excel Worksheet Functions 3 November 22nd 05 08:31 PM
dealing with very long numbers 149047 Excel Discussion (Misc queries) 3 July 7th 05 01:45 PM


All times are GMT +1. The time now is 03:51 PM.

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"