Hello,
Learning VBA on the go here..
1. Trying to compare two workbooks
2. Highlight the differences
The data in both the workbooks looks almost the same. However, I don't know how I can compare A1 and B1 values against the the other workbook. That is my challenge. I don;t know much VBA. I have something like this, but it is not doing what I want it to do.. sigh!
Sub CompareWorkbooksTwo()
Dim wbWorkbookOne As Workbook
Dim wbWorkbookTwo As Workbook
Application.ScreenUpdating = False
wb1ws1 = Workbooks("Copy Test_Sheet.xlsm").Worksheets("Functions_SS").Range("A2:B2").Value 'Assumes the first workbook name is 'Book1' and that it's open in the current session.
wb2ws2 = Workbooks("table_export.xls").Worksheets("ExportWorksheet").Range("A2:B2").Value 'Assumes the second workbook name is 'Book2' and that it's open in the current session.
For i = LBound(wb1ws1) To UBound(wb1ws1)
If wb1ws1(i, 1) = wb2ws2(i, 1) Then
blnSame = True
Else
Sheets("Functions").Activate
' Order no longer exists so highlight
Range(i, 1).Select
With Selection.Interior
.PatternColorIndex = xlAutomatic
.Color = 5287936
.TintAndShade = 0
.PatternTintAndShade = 0
End With
blnSame = False
Exit For
End If
Next i
If blnSame = True Then
MsgBox "data is the same"
Else
MsgBox "data is different"
End If
End Sub
For EX:
IDS Users
FID1 User A
FID2 UserB
FID1 UserA
FID2 UserB
FID1 User A
FID2 UserB
FID1 UserA
FID2 UserC
FID1 User A
FID2 UserB
FID1 UserA
FID2 UserB
Bookmarks