Sub Akulka2(): Dim wt As Workbook, wy As Workbook, wo As Workbook
Dim wtd As Worksheet, wyd As Worksheet, wod As Worksheet, FNT As String, FNY As String
Dim r As Long, c As Long, lr As Long, lc As Long, i As Long, j As Long, WI As String
Dim T As String, Y As String, n As Integer, k As Long, WF As Object
lr = 1: lc = 1: r = 1: c = 1 'Did you want to skip weekends and holidays?
n = Val(InputBox("How many days ago is the latest comparison file - 0,1,2,3 etc?"))
T = Replace(CStr(Date - n), "/", ""): Y = Replace(CStr(Date - n - 1), "/", "")
GetFiles: If n > 10 Then Exit Sub
FNT = Application.GetOpenFilename: FNY = Application.GetOpenFilename
VerifyFiles:
If InStr(1, FNT, T) And InStr(1, FNY, Y) = 0 Then
n = n + 1: GoTo GetFiles: End If
Workbooks.Open FNT: Set wt = ActiveWorkbook: Workbooks.Open FNY: Set wy = ActiveWorkbook
Set wo = Workbooks("Output.xlsx"): wo.Activate: Set WF = WorksheetFunction
For n = 1 To wt.Worksheets.Count: WI = wt.Sheets(n).Name
Set wtd = wt.Worksheets(WI): Set wyd = wy.Worksheets(WI)
For Each wod In wo.Worksheets
If wod.Name = ("diff" & WI) Then GoTo Setwod
Next
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "diff" & WI
Setwod: Set wod = wo.Worksheets("diff" & WI)
GetTableLimits: Do Until WF.CountA(wtd.Columns(c)) <> 0: c = c + 1
If c >= Columns.Count Then
GoTo GetAnother: End If
Loop
Do Until WF.CountA(wtd.Rows(r)) <> 0: r = r + 1: Loop
lr = r: Do Until WF.CountA(wtd.Rows(lr + 1)) = 0: lr = lr + 1: Loop
lc = c: Do Until WF.CountA(wtd.Columns(lc + 1)) = 0: lc = lc + 1: Loop
For j = r + 1 To lr: For i = c + 1 To lc
If wtd.Cells(j, i) <> wyd.Cells(j, i) Then
k = k + 1: wtd.Range(wtd.Cells(j, c), wtd.Cells(j, lc)).Copy
wod.Cells(k, 1).PasteSpecial xlPasteValues
wod.Cells(k, lc - c + 2) = wt.Name: wod.Cells(k, lc - c + 3) = "Row" & j
k = k + 1: wyd.Range(wyd.Cells(j, c), wyd.Cells(j, lc)).Copy
wod.Cells(k, 1).PasteSpecial xlPasteValues
wod.Cells(k, lc - c + 2) = wy.Name: wod.Cells(k, lc - c + 3) = "Row" & j
k = k + 2: GoTo GetNext: End If: Next i
GetNext: Next j
c = lc + 3: GoTo GetTableLimits
GetAnother: c = 1: lc = 1: r = 1: lr = 1: k = 0: Next n
End Sub
Bookmarks