can an =if formula have a message box?

smiler44

Registered User.
Local time
Today, 11:02
Joined
Jul 15, 2008
Messages
678
Is it possible for an =if formula to show a message box if a condition is met? for example

=if A1 <> A2 then msgbox ("Error please check")

could the same formula be used to stop a macro running if the above criteria is met?



thanks smiler44
 
Last edited:
Although not a formula I have found some code from the internet that with a small tweek will do what I need.

I can include this code into an existing subroutine.
feeling pleased with myself.

solved this, how to send an email with and attachment and signature, and how to get next Monday date.

Code:
Private Sub test2()
bla
bla
bla

 If Sheet1.Range("B1") <> Sheet1.Range("A1") Or _
 Sheet1.Range("B2") <> Sheet1.Range("A2") Or _
 Sheet1.Range("B3") <> Sheet1.Range("A3") Then
 MsgBox "There is an error please check"
exit sub
 End If
bla
bla
bla

 End Sub

smiler44
 
More "OR" logic can be added as needed. Here is the format. It is not a message box, it only brings the message to the cell.
=IF(Sheet2!A1 <>Sheet1!A1, "good", "Dude! That is excessive.")
 
thanks RX, I have now implemented my solution but have tested yours.

I cant face changing my code as in the last few days I have had to make over 22,500 changes having been asked to present data in a different format.

smiler44
 
Was interrupted before finishing my thought.
The Notes (N) are also another way to display information in Excel:
To add a comment to a formula, use the following form:
Formula + N("your comment")
For instance, the following formula contains a note that explains the formula's purpose:

=($C1-$B1 + ($B2>$C2))-$D2+N("Returns the elapsed time between two time values")

Also:
The Data Validation is very powerful and not well documented.
Highlight a cell - go to the Data menu. choose Data validation. in Settings - choose Formula. Note, there is an Error alert.

However, Data validation has issues with refresh. You did come up with the best solution for your problem.
 

Users who are viewing this thread

Back
Top Bottom