ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   IF NOT (https://www.excelbanter.com/excel-discussion-misc-queries/32784-if-not.html)

Nick

IF NOT
 
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


Hi

I would suggest having a look at Data|Validation. It will do just what you
want!
Have a look he http://www.contextures.com/xlDataVal01.html for more
information and examples.

--
Andy.


"Nick" wrote in message
...
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




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

"Andy B" wrote:

Hi

I would suggest having a look at Data|Validation. It will do just what you
want!
Have a look he http://www.contextures.com/xlDataVal01.html for more
information and examples.

--
Andy.


"Nick" wrote in message
...
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





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

Nick wrote:

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

"Andy B" wrote:


Hi

I would suggest having a look at Data|Validation. It will do just what you
want!
Have a look he http://www.contextures.com/xlDataVal01.html for more
information and examples.

--
Andy.


"Nick" wrote in message
...

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



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

--
HTH

Bob Phillips

"Nick" wrote in message
...
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

"Andy B" wrote:

Hi

I would suggest having a look at Data|Validation. It will do just what

you
want!
Have a look he http://www.contextures.com/xlDataVal01.html for more
information and examples.

--
Andy.


"Nick" wrote in message
...
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







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" wrote:

"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

Nick wrote:

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

"Andy B" wrote:


Hi

I would suggest having a look at Data|Validation. It will do just what you
want!
Have a look he http://www.contextures.com/xlDataVal01.html for more
information and examples.

--
Andy.


"Nick" wrote in message
...

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





All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com