K
K
Hi all, I have name in column A like see below
A………..col
Denise Buky
John Well
Sophy Bell
and I have files in folder "C:\Record" like see below
Record Sheet - Denise Buky.xls
Record - Roy William.xls
Record (John Well).xls
Record Sheet Craig Brown.xls
Record - Sophy Bell.xls
Record Sheet - Dean Owen.xls
I need macro which should check names in column A and only open those
files from above folder in which that name match or appear. I tried
doing this with below macro but this opens up all the files in
folder. Please can any friend can help that how can i do it.
Sub test()
fldrName = "C:\Record"
fName = Dir(fldrName & "\*.xls")
lastcl = Workbooks("Data.xls").Sheets("Sheet1").Cells(Rows.Count,
"A").End(xlUp).Row
Do While fName <> ""
Set c = Workbooks("Data.xls").Sheets("Sheet1").Range("A2:A" &
lastcl).Find(What:=fName, _
LookIn:=xlValues, LookAt:=xlWhole)
If c Is Nothing Then
Set bk = Workbooks.Open(Filename:=fldrName & "\" & fName)
bk.Close False
End If
fName = Dir()
Loop
End Sub
A………..col
Denise Buky
John Well
Sophy Bell
and I have files in folder "C:\Record" like see below
Record Sheet - Denise Buky.xls
Record - Roy William.xls
Record (John Well).xls
Record Sheet Craig Brown.xls
Record - Sophy Bell.xls
Record Sheet - Dean Owen.xls
I need macro which should check names in column A and only open those
files from above folder in which that name match or appear. I tried
doing this with below macro but this opens up all the files in
folder. Please can any friend can help that how can i do it.
Sub test()
fldrName = "C:\Record"
fName = Dir(fldrName & "\*.xls")
lastcl = Workbooks("Data.xls").Sheets("Sheet1").Cells(Rows.Count,
"A").End(xlUp).Row
Do While fName <> ""
Set c = Workbooks("Data.xls").Sheets("Sheet1").Range("A2:A" &
lastcl).Find(What:=fName, _
LookIn:=xlValues, LookAt:=xlWhole)
If c Is Nothing Then
Set bk = Workbooks.Open(Filename:=fldrName & "\" & fName)
bk.Close False
End If
fName = Dir()
Loop
End Sub