how to use if statement for range steps?

  • Thread starter Thread starter Mansoor
  • Start date Start date
M

Mansoor

If i want : X<66 then Y=2000 and if 66<X<100 then Y=3200 and 100<X<120 then
Y=4000 so on....... for X----> range (66,400), how to program it?
 
Hi Mansoor,

One way would be using a case statement similar to below. Obviously
the feasability of this depends on just how many intervals you want to
program on the way to 66,400. Note that I dim'd y as an integer, so it
will die if you try to make it 66,400.
If you have too many steps for this method, you could maybe try to
fina a mathematical pattern and build a formula? Hard to say without
seeing all your intervals.

Sub CaseDemo()
Dim x As Integer, y As Integer

x = InputBox("Please enter a number for x:")

Select Case x

Case Is < 66
y = 2000

Case 66 To 100
y = 3200

Case 101 To 120
y = 4000

Case Else
y = 5000

End Select

MsgBox "Seeing as you chose " & x & ", y is now: " & y

End Sub

Cheers,
Ivan.
 
Case Is < 66
y = 2000

Case Is <= 100
y = 3200

Case Is <= 120
y = 4000

Case Else
y = 5000

End Select
 

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