Feb 27 2024 11:10 AM
Hi!
How do I compare values in sheet 1 and sheet 2, and display it on sheet3?
Example:
Sheet 1 has the following columns:
ID
Age
Address
Sheet 2 has the following columns:
Age of bith
Street
Global ID
How do I, on sheet 3, make the Excel able to compare for example, ID on the sheet 1 , it searches for a match in the sheet 2, and if it finds a match it says "match or no match" on sheet 3?
Feb 29 2024 02:25 AM
You can maybe achieve this comparison using Excel formulas.
Here's a step-by-step proposal to compare values in Sheet1 and Sheet2 and display the results on Sheet3:
1. Set Up Sheet3:
2. Enter Unique Identifiers:
3. Write the Comparison Formula:
4. Drag the Formula Down:
5. Adjust Cell References:
6. Review the Results:
By following these steps, you can compare values between two Excel sheets using a unique identifier and display the results on a third sheet. This method does not require the use of macros or VBA.
If you would like to use VBA, here is a suggested solution.
Vba Code is untested, please backup your file.
Sub CompareSheets()
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Dim lastRow1 As Long, lastRow2 As Long, i As Long, j As Long
Dim matchFound As Boolean
' Define the worksheets
Set ws1 = ThisWorkbook.Sheets("Sheet1") ' Change "Sheet1" to the name of your first sheet
Set ws2 = ThisWorkbook.Sheets("Sheet2") ' Change "Sheet2" to the name of your second sheet
Set ws3 = ThisWorkbook.Sheets("Sheet3") ' Change "Sheet3" to the name of your third sheet
' Find the last row in each sheet
lastRow1 = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row
lastRow2 = ws2.Cells(ws2.Rows.Count, "C").End(xlUp).Row
' Loop through the IDs in Sheet1
For i = 2 To lastRow1 ' Assuming data starts from row 2 and ID is in column A
matchFound = False
' Loop through the Global IDs in Sheet2
For j = 2 To lastRow2 ' Assuming data starts from row 2 and Global ID is in column C
If ws1.Cells(i, "A").Value = ws2.Cells(j, "C").Value Then
' If a match is found, write "Match" to Sheet3
ws3.Cells(i, "B").Value = "Match"
matchFound = True
Exit For
End If
Next j
' If no match is found, write "No Match" to Sheet3
If Not matchFound Then
ws3.Cells(i, "B").Value = "No Match"
End If
Next i
End Sub
The text, steps and the code were created with the help of AI.
Hope this will help you.
Was the answer useful? Mark as best response and like it!
This will help all forum participants.