How to check two fields in excel and act by that?

[Solved/Closed]
Report
Posts
3
Registration date
Sunday April 7, 2013
Status
Member
Last seen
April 12, 2013
-
Posts
3
Registration date
Sunday April 7, 2013
Status
Member
Last seen
April 12, 2013
-
Hello,

Can anybody help? I would need very simple macro to check two cells.
A1 will be name
A2
A3 will be second namew
A4

Does A2=A4

If same comes window "OK!" 5 seconds pop up.
If not same then Big pop up "Warning! CODES TO NOT MATCH"
and read again button to press with mouse

barcode reader is putting enter to the end so it would be good if it clears the fields after check.

Can anybody help?

Would be Great help.

3 replies

Posts
2818
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
October 18, 2021
486
Hi Akaldojad,

Assuming A2 is entered first, try this code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A4")) Is Nothing Or _
Range("A4") = vbNullString Then Exit Sub

If Range("A2") = Range("A4") Then
CreateObject("WScript.Shell").Popup "OK!", 5, "This closes itself in 5 seconds"
Else: MsgBox Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10) & _
"Warning! CODES DO NOT MATCH" & Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10), vbExclamation
MsgBox "Please read again", vbInformation
End If

Range("A2").ClearContents
Range("A4").ClearContents

End Sub

To implement the code, right-click the sheets tab and paste the code in the big white field.

Best regards,
Trowa
Posts
3
Registration date
Sunday April 7, 2013
Status
Member
Last seen
April 12, 2013

Thanks! Working like charm:)
Posts
3
Registration date
Sunday April 7, 2013
Status
Member
Last seen
April 12, 2013

Thanks! Its working like should.