I get a report daily and it has around 8500 lines on it, I have been trying to make a macro that will do what I have been doing manually. The problem with the report is that all the lines are not the same format(i.e Line 1: number,text,text,number and Line 2: text, number, number, text).
I want to compare the new file to the old file and output the new differences. I can get the macro to run through the 2 files but it isn't flagging any of the lines as different but I know they are.
Sub test()
Dim yesterdayFile As String
Dim todayFile As String
yesterdayFile = Application.GetOpenFilename()
todayFile = Application.GetOpenFilename()
Dim yesterdayLine As String
Dim todayLine As String
Dim txt As String
Dim i, j, k, sameLine As Integer
Dim wkbTemp As Workbook
i = 1
j = 1
k = 1
sameLine = 0
Open yesterdayFile For Input As #1
Do Until EOF(1)
sameLine = 1 'reset write operator
Open todayFile For Input As #2
Line Input #1, yesterdayLine
Do Until EOF(2)
Line Input #2, todayLine
If StrComp(yesterdayLine, todayLine) = 0 Then 'compare lines in files if same then flag write operator to 1
sameLine = 1
End If
j = j + 1 'inner loop counter
Loop
If sameLine = 0 Then 'if write operator is not active then output line
Cells(i, 1) = yesterdayLine
i = i + 1 'counter for cells
End If
Close #2
k = k + 1 'outer loop counter
Loop
'test line to see if its eof
Cells(1, 10) = i
Cells(2, 10) = j
Cells(3, 10) = k
Close #1
End Sub
Test files being used to run the test faster:
Yesterday File:
10001,April,Apple
10002,Book,Bush
10004,Dog,Days
10006,Free,Food
10008,Happy,Help
10009,Ikky,Icing
10010,Jamming,Jupiter
Today File:
10001,April,Apple
10002,Book,Bush
10003,Cat,Cattle
10004,Dog,Days
10005,Echo,Eggg
10006,Free,Food
10007,Good,Game
10008,Happy,Help
10009,Ikky,Icing
10010,Jamming,Jupiter
Note: In the real data there is no "unique ID field"
Counters end with correct numbers so I know its running through the recursions
EDIT: I know this can be done easily with other languages, but I can only access excel vba from my work terminal and can't take files off network.