Help to check if else statements

Closed
Report
-
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
-
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 reply

Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
803
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