Consulting

Results 1 to 2 of 2

Thread: Open workbooks and compare cells

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    8
    Location

    Open workbooks and compare cells

    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.
    Ex.
    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
    Insea

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is some code to loop and open the files. Plug the comparison code in

    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •