Okay. I was on the right track... here's my code thus far:
Option Explicit
Option Base 1
Sub CompareDatesAcrossWorkbooks()
Dim Filename(5) As String
'CLfn As String, GCfn As String, USfn As String, ECfn As _
String, ESfn As String
'Dim CLrc As Integer, GCrc As Integer, USrc As Integer, ECrc _
As Integer, ESrc As Integer 'These are number of rows in each file
Dim tWB As Workbook, aWB As Workbook
Dim i As Integer, j As Integer, match As Integer, nomatch As _
Integer, nr As Integer
Dim Workbook(5) As Workbook
Set tWB = ThisWorkbook
Columns("A:D").ClearContents
Filename(1) = "C:\Users\drkle\Desktop\Desktop Transfer Material\Stock Market\TradeStation\Correlation data\CLdata.csv"
Filename(2) = "C:\Users\drkle\Desktop\Desktop Transfer Material\Stock Market\TradeStation\Correlation data\GCdata.csv"
Filename(3) = "C:\Users\drkle\Desktop\Desktop Transfer Material\Stock Market\TradeStation\Correlation data\USdata.csv"
Filename(4) = "C:\Users\drkle\Desktop\Desktop Transfer Material\Stock Market\TradeStation\Correlation data\ECdata.csv"
Filename(5) = "C:\Users\drkle\Desktop\Desktop Transfer Material\Stock Market\TradeStation\Correlation data\ESdata.csv"
match = 0
nomatch = 0
For i = 1 To 5:
Workbooks.Open Filename(i)
Workbook(i) = Filename(i)
'Set aWB = Workbook(i)
Next i
Range("A1").CurrentRegion.Select
nr = Selection.Rows.Count
For j = 2 To nr:
If Workbook(1).Cells(j, 1) = Workbook(2).Cells(j, 1) And _
Workbook(2).Cells(j, 1) = Workbook(3).Cells(j, 1) And _
Workbook(3).Cells(j, 1) = Workbook(4).Cells(j, 1) And _
Workbook(4).Cells(j, 1) = Workbook(5).Cells(j, 1) Then
match = match + 1
Else
nomatch = nomatch + 1
End If
Next j
For k = 1 To 5:
Workbook(i).Close SaveChanges:=False
Next k
Range("A1").Value = match 'Doesn't matter whether .Value is at the end
Range("A2") = nomatch
Range("B1") = "dates matched across all five WBs"
Range("B2") = "dates did not match across all five WBs"
End Sub
In the "For i" loop, as written I get an "object variable or with block variable not set." If I comment out the second line and uncomment out the third line, though, then it works. Why?
Also in the "For j" loop, I get the same "object variable or with block variable not set" on the long compound if line (four conditions). Why?
Thank you!
Bookmarks