Compare Excel document to another file

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
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.
Locked
User avatar
kodyleonard
Posts: 2
Joined: Thu Dec 06, 2007 2:58 am

Compare Excel document to another file

Post by kodyleonard » Thu Dec 06, 2007 3:03 am

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?

User avatar
kodyleonard
Posts: 2
Joined: Thu Dec 06, 2007 2:58 am

Compare Excel document to another file

Post by kodyleonard » Thu Dec 06, 2007 6:48 am

I got them comparing the files, but how would I use them to delete matching entries?

User avatar
jvierra
Posts: 13807
Joined: Tue May 22, 2007 9:57 am
Contact:

Compare Excel document to another file

Post by jvierra » Thu Dec 06, 2007 10:38 am

If you want two files to be identical just copy the first file over the second file. They will then both be the same.

Easiest way.

User avatar
jvierra
Posts: 13807
Joined: Tue May 22, 2007 9:57 am
Contact:

Compare Excel document to another file

Post by jvierra » Fri Dec 07, 2007 1:53 am

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.

Locked