Hello Bob@Sun,
I fixed the macro to sum each representative's count based on the each day of the month. Here is the amended macro.
'Thread: http://www.excelforum.com/excel-programming/729324-count-data-from-multiple-files.html#post2307113 'Poster: Bob@Sun 'Written: May 15, 2010 'Updated: May 16, 2010 'Author: Leith Ross Sub CountCalls() Dim CalcWks As Worksheet Dim FileName As String Dim FilePath As String Dim Person As Variant Dim Month As Integer Dim NameList As Range Dim NameRng As Range Dim RngEnd As Range 'Change the folder to where your files are stored FilePath = "C:\Documents and Settings\Admin.ADMINS\My Documents\Excel Forum Folders\Bob@Sun" Set CalcWks = ThisWorkbook.Worksheets("Sheet1") Set NameRng = CalcWks.Range("A3") Set RngEnd = CalcWks.Cells(Rows.Count, NameRng.Column).End(xlUp) Set NameRng = IIf(RngEnd.Row > NameRng.Row, CalcWks.Range(NameRng, RngEnd), NameRng) Set NameList = NameRng Application.ScreenUpdating = False FileName = Dir(FilePath & "\") Do While FileName <> "" If FileName Like "*_########.xls" Then Set Wkb = Workbooks.Open(FilePath & "\" & FileName) Month = Val(Mid(Wkb.Name, 14, 2)) Set NameRng = Wkb.Worksheets("Sheet1").Range("L2") Set RngEnd = NameRng.Parent.Cells(Rows.Count, NameRng.Column).End(xlUp) Set NameRng = IIf(RngEnd.Row > NameRng.Row, NameRng.Parent.Range(NameRng, RngEnd), NameRng) For Each Person In NameList Person.Offset(0, Month) = Person.Offset(0, Month) + WorksheetFunction.CountIf(NameRng, Person) Next Person Wkb.Close False End If FileName = Dir() Loop Application.ScreenUpdating = True End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello Bob@Sun,
I don't understand your last post. It is looks to be a repost of the previous one. The macro in my last post fixes the monthly total problem. Did you not run it? Is there another problem? If so, please give me examples of the problems.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Oh ok,
My problem now is that I am trying to change the countif function with Evaluate("Sumproduct.....), but I am having problems with that.
The problem comes when declaring " & Person &" in the formula. If I write just the name like this ""Peter"" everything is ok, but when I chage it to Person I am getting error.For Each Person In NameList Person.Offset(0, Month) = Application.Evaluate("SUMPRODUCT(--(L1:L100=" & Person & "),--(M1:M100=""OK""))") + Person.Offset(0, Month) Next Person
What is wrong?
Last edited by Bob@Sun; 05-16-2010 at 02:59 PM.
Hello Bob@Sun,
"Person" is a cell in the range "NameList". NameList is the range of names in column "A" of "Sheet1" in workbook "Calculate Data.xls". Person represents the cell as a Range Object and not just the contents of the cell.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
How can I transfer Person to represent the contents of the cell?
Hello Bob@Sun,
Try this ...
& Person.Text &
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
I get the "Type mismatch" error
I removed this...
+ Person.Offset(0, Month)
and I got true, but in the cell I still get the #NAME? error? while in the inmidiate window I am getting the names wright.
Hello Bobo@Sun,
I don't know what the problem is because I don't understand the logic of the statement.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
If this is the whole code...
If I run the code I am gettting "type mismatch" error.Sub CountCalls() Dim CalcWks As Worksheet Dim FileName As String Dim FilePath As String Dim Person As Variant Dim Month As Integer Dim NameList As Range Dim NameRng As Range Dim RngEnd As Range 'Change the folder to where your files are stored FilePath = "D:\Documents\EXCEL VBA\TESTING" Set CalcWks = ThisWorkbook.Worksheets("Sheet1") Set NameRng = CalcWks.Range("A3") Set RngEnd = CalcWks.Cells(Rows.Count, NameRng.Column).End(xlUp) Set NameRng = IIf(RngEnd.Row > NameRng.Row, CalcWks.Range(NameRng, RngEnd), NameRng) Set NameList = NameRng Application.ScreenUpdating = False FileName = Dir(FilePath & "\") Do While FileName <> "" If FileName Like "*_########.xls" Then Set Wkb = Workbooks.Open(FilePath & "\" & FileName) Month = Val(Mid(Wkb.Name, 14, 2)) Set NameRng = Wkb.Worksheets("Sheet1").Range("L2") Set RngEnd = NameRng.Parent.Cells(Rows.Count, NameRng.Column).End(xlUp) Set NameRng = IIf(RngEnd.Row > NameRng.Row, NameRng.Parent.Range(NameRng, RngEnd), NameRng) For Each Person In NameList Person.Offset(0, Month) = Application.Evaluate("SUMPRODUCT(--(L1:L100=" & Person.Text & "),--(M1:M100=""OK""))") _ + Person.Offset(0, Month) Next Person Wkb.Close False End If FileName = Dir() Loop Application.ScreenUpdating = True End Sub
I guess I have to cange something in this part to make it work...
For Each Person In NameList Person.Offset(0, Month) = Application.Evaluate("SUMPRODUCT(--(L1:L100=" & Person.Text & "),--(M1:M100=""OK""))") _ + Person.Offset(0, Month) Next Person
I have chage the code to this.....Sub CountCalls() Dim CalcWks As Worksheet Dim FileName As String Dim FilePath As String Dim Person As Variant Dim Month As Integer Dim NameList As Range Dim NameRng As Range Dim RngEnd As Range 'Change the folder to where your files are stored FilePath = "D:\Documents\EXCEL VBA\TESTING" Application.ScreenUpdating = False FileName = Dir(FilePath & "\") Do While FileName <> "" If FileName Like "*_########.xls" Then Set Wkb = Workbooks.Open(FilePath & "\" & FileName) Month = Val(Mid(Wkb.Name, 14, 2)) Set NameRng = Wkb.Worksheets("Sheet1").Range("L2") Set RngEnd = NameRng.Parent.Cells(Rows.Count, NameRng.Column).End(xlUp) Set NameRng = IIf(RngEnd.Row > NameRng.Row, NameRng.Parent.Range(NameRng, RngEnd), NameRng) ReDim NamesFound(0) As String ReDim NamesFound(50) As String i = 0 For Each Item In NameRng Nameaddress = Item.Address If IsInArray(Item, NamesFound) = False Then NamesFound(i) = Item Wkb.Activate Count = Application.Evaluate("SUMPRODUCT(--(L1:L100=" & Nameaddress & "),--(M1:M100=""OK""))") With ThisWorkbook .Activate Cells.Find(What:=NamesFound(i), After:=ActiveCell, LookIn:=xlFormulas, LookAt _ :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False).Select Selection.Offset(0, Month).Value = Selection.Offset(0, Month).Value + Count End With Else End If i = i + 1 Next Item Wkb.Close False End If FileName = Dir() Loop Application.ScreenUpdating = True End Sub
and this is doing the job
Leith and JBeaucaire,
Thanks for the help!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks