ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   GREATER THAN (https://www.excelbanter.com/excel-programming/323156-greater-than.html)

[email protected]

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


Tom Ogilvy

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

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
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




CB Hamlyn

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

wrote in message
oups.com...
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





All times are GMT +1. The time now is 12:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com