Copying only certain workbooks to a master file based on a criteria

T

thegetch1

Hi,

I have a folder with a changing number of status reports in it. Each is
standardized and only contains one tab, "Status Report".

Each status report has a cell (always B10) categorizing what type it
is.

I then have a "Infra Crit Master" that originally will have one tab
"Summary" also in the folder.

What I would like is every time the master file is opened, it will
search the folder for workbooks where B10 = True on the "Status Report"
tab. It will then make a copy of that worksheet and place this
worksheet after "Summary" in "Infra Crit Proj."

I'm not proficient at VB and cobbled together this piece of code from
other topics:

Private Sub Workbook_Open()
Dim i As Integer, wb As Workbook
With Application.FileSearch
.NewSearch
.LookIn = "\\lm-intm-01\clientdata$\n0148234\Desktop\Status Report"
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count

Set wb = Workbooks.Open(Filename:=.FoundFiles(i))

If (wb.Worksheets("Status Report").Range("B10") = "TRUE") Then
wb.Worksheets("Status Report").copy
After:=Workbooks("Infra Crit Proj").Sheets("Summary")
End If
Next i
End With

End Sub

I understand most of it, but get lost at the actual copying part, not
sure of any of the conventions for refering to workbooks, worksheets,
etc. Suffice to say it doesn't work.

Any help would be greatly appreciated. Thanks!
 
D

Dave Peterson

What happens when you try it?

Could it be as simple as a line wrap problem?

If (wb.Worksheets("Status Report").Range("B10") = "TRUE") Then
wb.Worksheets("Status Report").copy _
After:=Workbooks("Infra Crit Proj").Sheets("Summary")
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top