'Updated: June 28, 2010 - Corrected previous errors
'Author: Leith Ross
'Thread: http://www.excelforum.com/excel-programming/734362-reconciliation-of-two-sets-of-data.html
'Poster: mccrimmon
'Posted: June 24, 2010
Sub Reconcile()
Dim Account As String
Dim Cell As Range
Dim Details As Variant
Dim R As Long
Dim RecWks As Worksheet
Dim RefNum As String
Dim Rng As Range
Dim RngEnd As Range
Dim TAJ As Object 'Transaction Journal (master)
Dim Wks As Worksheet
Set RecWks = Worksheets("Rec")
Set Wks = Worksheets("Master")
Set Rng = Wks.Range("A2:I2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
Set TAJ = CreateObject("Scripting.Dictionary")
TAJ.CompareMode = vbTextCompare
For Each Cell In Rng.Columns(3).Cells
Account = Trim(Cell)
RefNum = Trim(Cell.Offset(0, 2))
If Account <> "" Then
If Not TAJ.Exists(Account & RefNum) Then
ReDim Details(3)
Details(0) = Cell.Offset(0, 3).Value 'Currency
Details(1) = Cell.Offset(0, 4).Value 'Date
Details(2) = Cell.Offset(0, 5).Value 'Value1
Details(3) = Cell.Offset(0, 6).Value 'Value2
TAJ.Add Account & RefNum, Details
End If
End If
Next Cell
'Clear any previous reconciliation errors
With RecWks
R = 2 'Header row for reconciliation errors
.Range(.Rows(R + 1), .Rows(Rows.Count)).Clear
End With
'Check each account against the master data in the TAJ
For Each Wks In Worksheets
If Wks.Name <> "Rec" And Wks.Name <> "Rec1" And Wks.Name <> "Master" Then
Set Rng = Wks.Range("A2:G2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))
For Each Cell In Rng.Columns(1).Cells
Account = Trim(Cell)
RefNum = Trim(Cell.Offset(0, 2))
Addx = Cell.Address
If Not TAJ.Exists(Account & RefNum) Then
'Is entry Missing
R = R + 1
RecWks.Cells(R, "B") = Wks.Name
RecWks.Cells(R, "C").Value = "Missing"
RecWks.Cells(R, "D") = Account
RecWks.Cells(R, "E") = RefNum
Else
'Check Details for errors
Details = TAJ(Account & RefNum)
If Cell.Offset(0, 3).Value <> Details(1) Then
R = R + 1
RecWks.Cells(R, "B") = Wks.Name
RecWks.Cells(R, "C").Value = "Incorrect Date"
RecWks.Cells(R, "D") = Account
RecWks.Cells(R, "E") = RefNum
RecWks.Cells(R, "G") = Cell.Offset(0, 3).Value
End If
If Cell.Offset(0, 4).Value <> Details(0) Then
R = R + 1
RecWks.Cells(R, "B") = Wks.Name
RecWks.Cells(R, "C").Value = "Incorrect Currency"
RecWks.Cells(R, "D") = Account
RecWks.Cells(R, "E") = RefNum
RecWks.Cells(R, "F") = Cell.Offset(0, 4).Value
End If
If Cell.Offset(0, 5).Value <> Details(2) Then
R = R + 1
RecWks.Cells(R, "B") = Wks.Name
RecWks.Cells(R, "C").Value = "Incorrect Value 1"
RecWks.Cells(R, "D") = Account
RecWks.Cells(R, "E") = RefNum
RecWks.Cells(R, "H") = Cell.Offset(0, 5).Value
End If
If Cell.Offset(0, 6).Value <> Details(3) Then
R = R + 1
RecWks.Cells(R, "B") = Wks.Name
RecWks.Cells(R, "C").Value = "Incorrect Value 2"
RecWks.Cells(R, "D") = Account
RecWks.Cells(R, "E") = RefNum
RecWks.Cells(R, "H") = Cell.Offset(0, 6).Value
End If
End If
Next Cell
End If
Next Wks
End Sub
Bookmarks