We help IT Professionals succeed at work.

# VBA Excel: code for checking if a number in a cell is >0 but <50

on
Hi Experts,

what code should I use to check if a number in an excel sheet cell,  is > 0 but < 50?

Many thanks

Lossie
Comment
Watch Question

## View Solution Only

Commented:
Can you please explain the question in deep? Actually what do you want to do if a value of a particular cell is >0 and <50?

Commented:
Select the cell(s) you want.
Go to the data tab, and click data validation.
Under settings wher it says allow, select whole number.
Under data, select between.
In minimum type 0.
In maximum type 50.

Regards

Commented:
Apologies, I meant:
In minimum type 1.
In maximum type 49.

Regards

Commented:

I am using VBA to step through a range of numbers.
If a number lies between 0 and 50, I will then take action on that row.
e.g.
If Worksheets(Sheet1).Cells(myRowinput, myColumn) > o and < 50  Then................

The code above does not work, but this is the thing I am trying to achieve.
Commented:
Sub CheckValue()
Dim ShObj As Worksheet
Dim lngMyRowInput As Long
Dim lngMyColInput As Long

lngMyRowInput = 1
lngMyColInput = 1
Set ShObj = ThisWorkbook.Worksheets(1) 'OR Set ShObj = ThisWorkbook.Worksheets("Sheet1")

If ShObj.Cells(lngMyRowInput, lngMyColInput).Value > 0 And ShObj.Cells(lngMyRowInput, lngMyColInput).Value < 50 Then