Tom,
Up front let me state that I truly appreciate ALL of the help!!!
I read your response late last night...and I have to admit this is
begining to push my understanding and knowledge of VBA.
I found some other posts about declaring variables in the way you
mentioned and have added sections of the code to mine and it seems to
work. It opens each M*wkbk and runs the calculations, moves to the next
column and does it for the next M*wkbk in the folder. WORKS GREAT!!!
I have two requests; One would you look at the code below and see if it
is in the most efficient way?
And, I plan to use this same basic code to work on additional projects
and the sumproduct there is a little more in depth than this one, based
on your solution before; would I do something like this: If you think
it best to repost as a new post for this I will...
=IF(INDEX(Mkt!F:F,MATCH(Summary!C42,MKT!$C:$C,0))="""",IF(ISERROR(SUMPRODUCT((s"&iwkbk&"htm!$A$1:$A$10000=Summary!C42....etc...for
EACH section?
Below is the original formula
=IF(INDEX(Mkt!F:F,MATCH(Summary!C42,Mkt!$C:$C,0))="",IF(ISERROR(SUMPRODUCT((SP2.htm!$A$1:$A$10000=Summary!C42)*(SP2.htm!$E$1:$E$10000="yes")*(SP2.htm!$A$1:$A$10000=Summary!C42)*(SP2.htm!$D$1:$D$10000="Is
this project 100% complete to
specifications?"))/SUMPRODUCT((SP2.htm!$A$1:$A$10000=Summary!C42)*(SP2.htm!$D$1:$D$10000="Is
this project 100% complete to
specifications?"))),"",SUMPRODUCT((SP2.htm!$A$1:$A$10000=Summary!C42)*(SP2.htm!$E$1:$E$10000="yes")*(SP2.htm!$A$1:$A$10000=Summary!C42)*(SP2.htm!$D$1:$D$10000="Is
this project 100% complete to
specifications?"))/SUMPRODUCT((SP2.htm!$A$1:$A$10000=Summary!C42)*(SP2.htm!$D$1:$D$10000="Is
this project 100% complete to specifications?"))),"Inactive")
Here is the entire code, at this point:
Sub MAPREPORT()
Dim lCount As Long
Dim wbResults As Workbook, wsFiles As Worksheet
Dim wbCodeBook As Workbook
Dim iWkbk As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = ThisWorkbook.Path
.FileType = msoFileTypeExcelWorkbooks
.FileName = "m*.htm"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults =
Workbooks.Open(FileName:=.FoundFiles(lCount), UpdateLinks:=0)
'Run Calculations
Windows("MAPReport.xls").Activate
Dim LastRow As Long
Dim lastcol As Long
iWkbk = iWkbk + 1
Set wbResults = Workbooks.Open(wsFiles.Range("M" &
iWkbk).Value).Worksheets(1)
With Worksheets("MAP")
lastcol = .Cells(2, Columns.Count).End(xlToLeft)(1, 2).Column
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
With .Range(.Cells(2, lastcol), .Cells(LastRow, lastcol))
.Formula = "=SUMPRODUCT((m" & iWkbk &
".htm!$A$1:$A$10000=$C2)*(m" & iWkbk & ".htm!$E$1:$E$10000=""Yes""))"
.Value = .Value
End With
End With
wbResults.Close SaveChanges:=True
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub