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

Solved/Closed
akaldojad Posts 3 Registration date Sunday April 7, 2013 Status Member Last seen April 12, 2013 - Apr 7, 2013 at 12:31 PM
akaldojad Posts 3 Registration date Sunday April 7, 2013 Status Member Last seen April 12, 2013 - Apr 12, 2013 at 03:27 AM
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.
Related:

3 responses

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Apr 8, 2013 at 11:11 AM
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
0
akaldojad Posts 3 Registration date Sunday April 7, 2013 Status Member Last seen April 12, 2013
Apr 12, 2013 at 03:26 AM
Thanks! Working like charm:)
0
akaldojad Posts 3 Registration date Sunday April 7, 2013 Status Member Last seen April 12, 2013
Apr 12, 2013 at 03:27 AM
Thanks! Its working like should.
0