Jagwarman
asked on
VBA MsgBox if two cells are not equal to one another
is it possible to put out an error message [box] if two cell do not equal one another.
I would like a message box to look up the word Balance and then if the cell 3 to it's right does not equal the cell 5 to the right of balance issue an error message saying Does not balance. Both cells should contain 0 and the result should be 0
Here's hoping!
Thanks
I would like a message box to look up the word Balance and then if the cell 3 to it's right does not equal the cell 5 to the right of balance issue an error message saying Does not balance. Both cells should contain 0 and the result should be 0
Here's hoping!
Thanks
Should it look for 'balance' in the entire sheet or a specific column? Can you provide an example workbook?
I would recommend using conditional formatting.
ASKER
I prefer to use vba because this is part of a much bigger VBA.
file attached. The Bals at the foot in row 50 should both be 0 which would mean the inputter has input a wrong amount somewhere.
If they insert new rows row 50 will move.
Thanks
Data-the-same-or-not.xlsx
file attached. The Bals at the foot in row 50 should both be 0 which would mean the inputter has input a wrong amount somewhere.
If they insert new rows row 50 will move.
Thanks
Data-the-same-or-not.xlsx
Here is a macro that will search column K for the word "Balance". It will then compare the cells 3 and 5 columns to the right. If they differ by more than 0.005, then a message is displayed.
Sub TestBalance()
Dim cel As Range
With ActiveSheet
On Error Resume Next
Set cel = .Columns("K").Find("Balance", LookAt:=xlPart)
If Not cel Is Nothing Then
If Abs(cel.Offset(0, 3).Value - cel.Offset(0, 5).Value) >= 0.005 Then _
MsgBox "Does not balance"
End If
On Error GoTo 0
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
byundt this is exactly what I am looking for. Many thanks. Brilliant