Link to home
Start Free TrialLog in
Avatar of david Jogers
david Jogers

asked on

Macro not looking in correct place to compare files.

I have this macro that I believe compares the data in file called "compare" with data in another folder of my choice of which I put the name in  the file called compare.

Its then meant to look within the folder for the file name and compare that with what I have in the file called "compare"

I tried running it and it says that that it cannot find the file that im comparing  because its on the desktop of my PC.   I don't have any files on the desktop.

All files are in a folder called compare of which has the compare macro file and all other files that it has to look in.

Any ideas?

Private Sub CommandButton1_Click()
Dim WBs As Workbook, WBc As Workbook, cpath As String
Dim WSs As Worksheet, WSc As Object
Dim i As Long, j As Long, k As Integer, C As Boolean, R As Integer
Set WBs = Application.ActiveWorkbook
cpath = Application.ThisWorkbook.Path
Set WSs = WBs.ActiveSheet
Set WBc = Workbooks.Open(cpath & "\" & WSs.Cells(3, 8))
Set WSc = WBc.Sheets(WSs.Cells(3, 9).Value)
i = 4

C = False
Do While WSs.Cells(i, 1) <> ""
    j = 2
    C = False
    Do While WSc.Cells(j, 1) <> "" And C = False
        R = 0
        k = 1
        Do While WSs.Cells(i, k).Value = WSc.Cells(j, k).Value And k < 5
            DoEvents
            k = k + 1
        Loop
        If k = 5 Then
            C = True
            Exit Do
        End If
        j = j + 1
    Loop
    If C = False Then
        WSs.Range("A" & i, "D" & i).Interior.ColorIndex = 6
    Else
        WSs.Cells(i, 5) = j
        WSs.Range("A" & i, "D" & i).Interior.ColorIndex = 2
    End If
    i = i + 1
Loop
End Sub

Open in new window

Avatar of Kimputer
Kimputer

Currently, you code will take the files in the same folder as the file you started the macro with.
Your assumption that it's "another folder of my choice", is not correct.
You would already know that because you are never presented a dialog to choose any folders, thereby, it could never even have been a folder of your choice.
ASKER CERTIFIED SOLUTION
Avatar of Fabrice Lambert
Fabrice Lambert
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of david Jogers

ASKER

Thanks fabrice..

Unfortunately I'm not that advanced and it's completely gone over top of my head. Can I have a cheek and ask if poss you can just amend my script??

Thanks in advance