#1   Report Post  
Nick
 
Posts: n/a
Default 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
  #2   Report Post  
 
Posts: n/a
Default

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



  #3   Report Post  
Nick
 
Posts: n/a
Default

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




  #4   Report Post  
Jerry W. Lewis
 
Posts: n/a
Default

"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


  #5   Report Post  
Bob Phillips
 
Posts: n/a
Default

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








  #6   Report Post  
Nick
 
Posts: n/a
Default

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"