Compare Excel document to another file
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- kodyleonard
- Posts: 2
- Last visit: Thu Dec 06, 2007 5:48 am
Compare Excel document to another file
I'm trying to get a script going that compares the contents of a spreadsheet with another file (another Excel file or .txt file). Anything found in the second file is deleted in the first file. Can anyone help me with this?
- kodyleonard
- Posts: 2
- Last visit: Thu Dec 06, 2007 5:48 am
Compare Excel document to another file
I got them comparing the files, but how would I use them to delete matching entries?
Compare Excel document to another file
FC has a switch which will dump ONLY the differences between list 1 and list 2.
To do this with script you would probably want to load both files into sorted arrays and then walk them and compare them in collated order. This is a pretty sophisticated script.
Start with using the FileSystemObject to open both files and read them into arrays then compare teh arrays in a loop structure.
For teh Excel you would open both spreadsheets and do a cell by cell comparison assuming the spreadsheets are nearly identical to begin with. If you know the potentail liits you can narrow the comparison using that as a criteria.
Example - all values are in column A betwenn rows 1 and 100. Blank cells are ignored.
for i = 1 to 100
if sheet1.cell(1,i) <> sheet2.cell(1, i ) then
' report difference.
end if
next
If you start with something like this perhaps we can get you giong in the right direction.
To do this with script you would probably want to load both files into sorted arrays and then walk them and compare them in collated order. This is a pretty sophisticated script.
Start with using the FileSystemObject to open both files and read them into arrays then compare teh arrays in a loop structure.
For teh Excel you would open both spreadsheets and do a cell by cell comparison assuming the spreadsheets are nearly identical to begin with. If you know the potentail liits you can narrow the comparison using that as a criteria.
Example - all values are in column A betwenn rows 1 and 100. Blank cells are ignored.
for i = 1 to 100
if sheet1.cell(1,i) <> sheet2.cell(1, i ) then
' report difference.
end if
next
If you start with something like this perhaps we can get you giong in the right direction.