Conditional statement

  • Thread starter Thread starter Hawk
  • Start date Start date
H

Hawk

I would like an IF statement to return TRUE if the value
in a cell is a number greater than 0. I would like to do
it in one statement, but I am having troubgle since VBA
does not do short circuit evaluation. I realize that I
can do:

If Isnumeric(Range("A1")) then
If Range("A1")> 0 then

However, it would be nice to do it in one statement. If I
try:

If Isnumeric(Range("A1")) and Range("A1")> 0 then

I get an error when the user enters a non-numeric value
due to the second half of the conditional. Any ideas
would be greatly appreciated (and NO I cannot use Excel's
built-in Data Validation). TIA...
 
This was a problem in XL97/VBA5 (and possibly earlier versions), but works
in XL2000 and later (VBA6)

Sub AACTester1()
If IsNumeric(Range("A1")) And Range("A1") > 0 Then
MsgBox "Cell OK"
Else
MsgBox "Cell not OK"
End If
End Sub
 
Can't think why you insist it is on one line, so this might not be what you
want

On Error Resume Next
If IsNumeric(Range("A1")) And Range("A1") > 0 Then
MsgBox "yes"
Else
MsgBox "no"
End If
On Error GoTo 0

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
I guess, but in the world of deals, this shouldn't be such a big one.
 

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