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.
This topic is 16 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
kodyleonard
Posts: 2
Last visit: Thu Dec 06, 2007 5:48 am

Compare Excel document to another file

Post by kodyleonard »

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
Last visit: Thu Dec 06, 2007 5:48 am

Compare Excel document to another file

Post by kodyleonard »

I got them comparing the files, but how would I use them to delete matching entries?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Compare Excel document to another file

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Compare Excel document to another file

Post by jvierra »

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.
This topic is 16 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked