GREATER THAN

J

john.9.williams

Hi,

Can anyone help me with some code, iwant to use an if statement,
declaring that if a varible is greater then 0 then do my then
statement. I cannot seem to get it right

i am using

if variable name > 0 then my action
 
T

Tom Ogilvy

sub Tester2()
Dim num as long
num = 10 - int(rnd()*20+1)
if num > 0 then
msgbox num & " is greater than 0"
else
msgbox num & " is less than or equal to 0"
End if
End Sub
 
C

CB Hamlyn

You've got the syntax correct.

If it doesn't work perhaps the variable isn't numeric or perhaps it's < or =
0?

As a simple example, the below declares intTestNumber as an Integer then
sets it to the value of Cell A1. Next it tests to see if it's greater than
0. If it is, it sets Cell A1 back to Zero.

Dim intTestNumber As Integer
intTestNumber = Range("A1").Value
if intTestNumber > 0 Then Range("A1").Value = 0

Hope that helps.
CB Hamlyn
 

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

Top