IF NOT

N

Nick

I am having a little difficulty trying to write a formula to display a
message if a certain cell does not contain the correct information. Can
anyone please help me with this.

I.e. If cell A1 does not contain 1 or 2 or 3 then display message "reenter
number"

Cheers
 
N

Nick

I have looked at the site and nothing seems to work or be useful. I'm working
in Visual basic within a long macro. Anyone got any tips on the code to
possibly use. At the moment I have

If Range("B12") = "1" or "2" or "3" Then
Range("A1").Select
Else If Range("B12") Is Not "1" or "2" or "3" Then
MsgBox "Re-enter Number"

An error message is displayed saying Compile error: Type Mismatch

Any ideas people
 
J

Jerry W. Lewis

"2" and "3" are not boolean values, hence the Type Mismatch error.

If [B12] = 1 Or [B12] = 2 Or [B12] = 3 Then
[A1].Select
Else
MsgBox "Re-enter Number"
[B12].Select
End If

Except for the [A1].Select, this could all be done by entering a
Data|Validation criteria from the worksheet menu, as has been previously
suggested in both of your related threads.

Jerry
 
B

Bob Phillips

With .Range("B12")
If .Value = "1" or .Value = "2" or .Value = "3" Then
Range("A1").Select
Else
MsgBox "Re-enter Number"
End If
End With
 
N

Nick

I have tried entering the suggested code. The message box is now displayed
everytime I press my printpreview button that the macro is assigned to, even
if the number in the cell is correct. Im not 100% confident on how to use
data validation, just thought there would be simple way of using visual basic
to enter the code.

Any other suggestions please

Jerry W. Lewis said:
"2" and "3" are not boolean values, hence the Type Mismatch error.

If [B12] = 1 Or [B12] = 2 Or [B12] = 3 Then
[A1].Select
Else
MsgBox "Re-enter Number"
[B12].Select
End If

Except for the [A1].Select, this could all be done by entering a
Data|Validation criteria from the worksheet menu, as has been previously
suggested in both of your related threads.

Jerry
I have looked at the site and nothing seems to work or be useful. I'm working
in Visual basic within a long macro. Anyone got any tips on the code to
possibly use. At the moment I have

If Range("B12") = "1" or "2" or "3" Then
Range("A1").Select
Else If Range("B12") Is Not "1" or "2" or "3" Then
MsgBox "Re-enter Number"

An error message is displayed saying Compile error: Type Mismatch

Any ideas people

:
 
Top