View Full Version : Open workbooks and compare cells

11-09-2007, 06:03 PM
I everybody!
I have 400 worbooks in the same folder (C:\Test), and i would like to open and compare two cells with the condition of the value in the two different cells are the same. If the value is the same give a OK, if not give me that information with the difference in a new file.
Cell1 Cell2 Difference File name
A5=2098 R1=2097 #1 DFL.xls

The second procedure of comparing, is I have 5 cells (B1, B2, B3, B4, B5) with different numbers and i want compare the SUM of this 5 cells with another one (C1).
If it is possible do the verification of values in the same procedure better.

Cell1 Cell2 Cell3 Cell4 Cell5 Cell6 Difference File Name

B1=2 B2=4 B3=6 B4=7 B5=8 C1=27 #0 DFL.XLS

The problem is that i have 400 files and i would like to open, Compare and close automatically.

thanks for your help

11-10-2007, 04:16 AM
Here is some code to loop and open the files. Plug the comparison code in

Sub LoopFolders()
Dim oFSO
Dim Folder As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("C:\myFiles")
For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
'do your stuff with the open workbook
ActiveWorkbook.Close savechanges:=False
End If
Next file

Set oFSO = Nothing

End Sub