DavyJones90
Board Regular
- Joined
- Feb 23, 2022
- Messages
- 62
- Office Version
- 365
- Platform
- Windows
HI guys, trying to create a macro which compares the values in 3 workbooks to eachother and then puts the outcome on a fourth workbook in the exact same cell as in the 3 checked, a little background knowledge is that there are 3 Analysts for a project. The analysis of these 3 are supposed to be compared on a daily basis, now sometimes it will happen that there are only 2 at which point these two should be compared and differences noted (this can be done based on the date (meaning if only 2 input todays date the third is ignored.
This is what I got. It ain't working and I have no Idea how to extend and it to checking 3 workbooks.
This is what I got. It ain't working and I have no Idea how to extend and it to checking 3 workbooks.
VBA Code:
Option Explicit
Sub Comparebooks()
Dim Analyst1 As Workbook, Analyst2 As Workbook, AutoArrows As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet, wsMatch As Boolean
Dim cell As Range
'Open a file dialog to select workbooks (optional)
Set Analyst1 = Workbooks("C:\Users\david_5oni1yh\OneDrive\Desktop\Server\Analyst1\Analyst1.xlsm\") ' This Ain't working (SCRIPT OUT OF RANGE)
Set Analyst2 = Workbooks("C:\Users\david_5oni1yh\OneDrive\Desktop\Server\Analyst2\Analyst2.xlsm\") ' This Ain't working (SCRIPT OUT OF RANGE)
If Analyst1.Worksheets.Count = Analyst2.Worksheets.Count Then
'Loop through worksheets
For Each ws1 In Analyst1.Worksheets
wsMatch = False
For Each ws2 In Analyst2.Worksheets
If ws1.Name = ws2.Name Then
wsMatch = True
'Compare the 2 worksheets
For Each cell In ws1.Range("A1").CurrentRegion
If cell.Value <> ws2.Range(cell.Address).Value Then
ThisWorkbook.cell.Interior.Color = vbYellow
MsgBox "Mismatch cell " & cell.Address & " in worksheet " & ws1.Name
End If
Next cell
Exit For
End If
Next ws2
If wsMatch = False Then ThisWorkbook.Tab.Color = vbYellow
Next ws1
Else
MsgBox "Worksheets mismatch"
End If
End Sub