View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Data Validation in Calculated Cells

Greg,

Copy the code below, right-click the sheet tab, select "View Code" and paste the code into the
window that appears. You may want to play with the various Exit Sub conditions....

HTH,
Bernie
MS Excel MVP


Private Sub Worksheet_Calculate()
If Range("C1").Value = "" Then Exit Sub
If Range("C2").Value = "" Then Exit Sub
If Range("C1").Value = 0 Then Exit Sub
If Range("C2").Value = 0 Then Exit Sub

If Range("C1").Value = Range("C2").Value Then
MsgBox "Hey! C1 is the same as C2!"
End If
End Sub


"Gregory Winters" wrote in message
...
I already know that the standard tool that comes with Excel only works with
data entry cells, but because of the context of more complex spreadsheets,
there has to be a way to perform simple validations (which render a similar
dialog to the user) when the results of his/her work are invalid in
calculated cells?!

My task is simple: Cell C1 renders a simple sum Fx from cells A1 and B1.
Cell C2 = A2 + B2, etc. All I need to have Excel do is tell the user right
away whenever C1=C2, or in batches in the event of Copy and Paste.

Any help would be greatly appreciated!

Greg