Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for "between" to values? 1

Status
Not open for further replies.

eon5

Technical User
Dec 31, 2007
47
ZA
Hi

I use the following code to act on when the value is smaller or equal to 5% and it works perfectly.

If Sheet9.Range("n" & y).Value <= 0.05 Then

I need some advice on the code if the macro should act on a number that is between 5% and 10%

Thanks

 
Perhaps

[tt]If Sheet9.Range("n" & y).Value > 0.05 AND _
Sheet9.Range("n" & y).Value <= 0.1 Then[/tt]

You could probably find some info on such by checking the help file, or do a bit of searching in these fora, too

Roy-Vidar
 
When working with multiple from/to value ranges as you are, I feel it's more readable to use Select/Case:
Code:
Select Case Sheet9.Range("N" & y).Value
    Case Is <= 0.05
        ' Value MUST BE <= 0.05
    Case Is <= 0.1
        ' Because the previous test failed, we know
        ' the Value MUST BE > 0.05 and will only land
        ' here if it is also <= 0.1
    Case Is <= 0.25
        ' Because the previous tests failed, we know
        ' the Value MUST BE > 0.1 and will only land
        ' here if it is also <= 0.25
    Case Else
        ' Because the previous tests failed, we know
        ' the Value MUST BE > 0.25. Additional tests
        ' could be added for more value ranges
End Select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top