Help to check if else statements

Closed
Rosi - Jul 6, 2009 at 10:57 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jul 6, 2009 at 10:23 PM
Hello,
I want to declare a name for the cell B25 from worksheet2. Let's call it "The Error".
Then, I want to check several statements to check "The Error" values.
For example, If "The Error" >= 1 and "The Error" <10
Message "Green range"
ElseIf "The Error" >=11 and "The Error" <15
Message "Red range"
Else
Message "Invalid"
End

Using Excel 2003, VBA

1 response

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Jul 6, 2009 at 10:23 PM
try this
the range name should be one word so use "the_error"
Sub test()
Dim rng As Range
Set rng = Range("the_error")
If rng >= 1 And rng < 10 Then
MsgBox "green range"
ElseIf rng >= 11 And rng < 16 Then
MsgBox "red range"
Else
MsgBox "invalid"
End If
End Sub
0