if statement dealing with numberical numbers and text

  • Thread starter Thread starter lovepeaceofmind
  • Start date Start date
L

lovepeaceofmind

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
 
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
 
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








- Show quoted text -

Thanks, it works as desired.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top