I have a ridiculous ancient spreadsheet that isn't made to pull reports from. I've already redone it for the future reports but unfortunately i have to go back and get info from the old ones.
Each workbook has 100+ worksheets, each worksheet named with the corresponding person's last name. I was able to create a loop to give me a list of the worksheet names in column a with the following code:
Columns 2 nd 3 i have an array formula to pull the first names and cost centers... then the rest of the columns are labeled 1 - 19, each of those representing activities. Each record consists of a project and how much time they spent on that project under the activities in the columns.Sub WorkSheetPull() dim i as Integer for i = 1 to worksheet.count Worksheets("Report").Cells(i, 1) = Worksheets(i).Name Next i End sub
Here's my problem.
I need a loop to go through each worksheet and search rows 18 thorugh 150, if the sum of the numbers in the row are >1 that means a value was entered on that row... and those numbers need to be pulled to the report spreadsheet....
I can't seem to put the code together correctlyHere are samples of some of my attempts:
Sub Records() Dim i As Integer Dim ws As Worksheet Dim Rw As Long Dim Cel, nRw, ac1 As Range Dim Projects As Range nRw = Worksheets("Project").Range("A65536").End(xlUp) For i = 3 To Worksheets.Count Worksheets("Projects").Cells(i, 1) = Worksheets(i).Name For Each ws In Worksheets Set Projects = Worksheets(i).Range("C18:C150") For Each Cel In Projects Rw = Application.CountA(Cel.EntireRow) If Rw > 1 Then Worksheets("projects").Cells(i, 4) = Worksheets(i).ac1.Value Loop Until Rw = 0 End Sub
This next one below actually worked perfectly but it only gives me the first record on the worksheet, i dont know how to get it to repeat the worksheet name on the next row of the report sheet if the employees sheet has more than one record. (Which it will for each month - see attached document)
I think i'm close but i can't wrap my head around this =( I just want the values in columns D through K and M through N if there's a value entered if not skip that row and go to the next until you get from row 18 to row 150 (some of the employees have 150 rows)....Sub ProjectPull1() 'Dim i, As Integer 'Dim R As Range For i = 2 To Worksheets.Count Worksheets("projects").Cells(i, 1) = Worksheets(i).Name If Not Worksheets(i).Range("C18") Is Nothing Then Worksheets("projects").Cells(i, 3) = Worksheets(i).Range("C18").Value End If If Not Worksheets(i).Range("D18") Is Nothing Then Worksheets("projects").Cells(i, 4) = Worksheets(i).Range("D18").Value End If If Not Worksheets(i).Range("E18") Is Nothing Then Worksheets("projects").Cells(i, 5) = Worksheets(i).Range("E18").Value End If If Not Worksheets(i).Range("F18") Is Nothing Then Worksheets("projects").Cells(i, 6) = Worksheets(i).Range("F18").Value End If If Not Worksheets(i).Range("G18") Is Nothing Then Worksheets("projects").Cells(i, 7) = Worksheets(i).Range("G18").Value End If If Not Worksheets(i).Range("H18") Is Nothing Then Worksheets("projects").Cells(i, 8) = Worksheets(i).Range("H18").Value End If If Not Worksheets(i).Range("i18") Is Nothing Then Worksheets("projects").Cells(i, 9) = Worksheets(i).Range("i18").Value End If If Not Worksheets(i).Range("J18") Is Nothing Then Worksheets("projects").Cells(i, 10) = Worksheets(i).Range("J18").Value End If If Not Worksheets(i).Range("K18") Is Nothing Then Worksheets("projects").Cells(i, 11) = Worksheets(i).Range("K18").Value End If If Not Worksheets(i).Range("M18") Is Nothing Then Worksheets("projects").Cells(i, 12) = Worksheets(i).Range("M18").Value End If If Not Worksheets(i).Range("N18") Is Nothing Then Worksheets("projects").Cells(i, 13) = Worksheets(i).Range("N18").Value End If Worksheets("projects").Cells(i, 14) = "=sum(RC4:RC13)" 'Column 2 = First name Next i End Sub
how should i proceed?
Last edited by DoriBeE; 05-17-2011 at 12:45 PM. Reason: I Figured it out ^_^
So you want to loop through each of the worksheets with a person's name (in your example file - Baez and Fusco) and for rows 18 to 150, if the sum of columns D to N > 0 then you want to copy the row to a Report sheet?
There's no Report sheet in your file. What does it look like?
I'm sorry, the worksheet is called "Projects". its the first one in the document.
This is the latest code i was attempting to work:
I'm not sure if it has somethin to do with the "next e" without checking for the value of the row within the loop... or something in the syntax is wrong but I'm getting close i just can't get all of the code together :*(Sub ActiveCellSearch() Dim i As Integer Dim ws As Worksheet Dim Rw As Long Dim strE As String For i = 2 To Worksheets.Count 'For Each ws In Worksheets Dim e As Integer For e = 18 To 150 strE = e Worksheets(i).Range("C" & strE).Select Rw = WorksheetFunction.Sum(Worksheets(i).Range("C" & strE & ":" & "N" & strE)) Do If Rw < 1 Then ActiveCell.EntireRow.Offset(1, 0).Select End If Loop Until Rw > 1 Worksheets("Projects").Cells(i, 1) = Worksheets(i).Name Worksheets("Projects").Cells(i, 4) = Worksheets(i).Cells(e, 3).Value Worksheets("projects").Cells(i, 5) = Worksheets(i).Cells(e, 4).Value Worksheets("Projects").Cells(i, 6) = Worksheets(i).Cells(e, 5).Value Worksheets("Projects").Cells(i, 7) = Worksheets(i).Cells(e, 6).Value Worksheets("Projects").Cells(i, 8) = Worksheets(i).Cells(e, 7).Value Worksheets("Projects").Cells(i, 9) = Worksheets(i).Cells(e, 8).Value Worksheets("Projects").Cells(i, 10) = Worksheets(i).Cells(e, 9).Value Worksheets("Projects").Cells(i, 11) = Worksheets(i).Cells(e, 10).Value Worksheets("Projects").Cells(i, 12) = Worksheets(i).Cells(e, 11).Value Worksheets("Projects").Cells(i, 13) = Worksheets(i).Cells(e, 12).Value Worksheets("Projects").Cells(i, 14) = Worksheets(i).Cells(e, 14).Value Worksheets("Projects").Cells(i, 15) = Worksheets(i).Cells(e, 15).Value Worksheets("Projects").Cells(i, 16) = "=sum(RC4:RC13)" Next e Next i End Sub
The report sheet ("Projects") lists the Last name and first name (first name will be a vlookup from a diff. spreadsheet on the network), then the code column corresponds to column C on the Baez and Fusco sheets...
so Yes, i want it to go through every sheet, if the sum of that row within columns D through N on the person's sheet is greater than one, that means they enetered a value for that month. If the sum is 0 it should move on to the next row until it gets to row 150 in every worksheet.
Last edited by DoriBeE; 05-09-2011 at 09:12 AM.
It seems a project can be listed more than once on an individuals sheet - eg on Fusco there is a Project 1 each month. What value do you want to be copied to the Projects sheet? The sum of them all? The most recent month? Only the first month?
Dion
Every project for each month should be listed. even if the project is blank (That jus means it wasn't project related, but time was still spent in an activity).
see the attached picture. ( i blacked the names out).
Something that just dawned on me (such an Idiot). Column P (in the 1st workbook attachment under either Fusco or Baez) has a grand total of everything in each row... if column P's value is > 0.01, then activity was entered and has to be included in the report. so there's no need to count the sum of the row if the sum is already at in column P. So that can be the indicator of which rows to bring over...
is copy and paste of values better than the route i was taking in my previous coding attempts?
See the code in thread response #3.
Hey everyone. I figured it out! ^_^ This worked for me:
Thank GOD! LOL I thought i was gonna go blind on this one! WoOT!Sub LoopAttempt() Dim i, e, r As Integer For i = 3 To Worksheets.Count e = 18 r = Worksheets("projects").Range("A$65536").End(xlUp).Row + 1 Do If Worksheets(i).Cells(e, "P") > 0.01 Then Worksheets("Projects").Cells(r, "A") = Worksheets(i).Name 'Worksheets("Projects").Cells(i, "B") = 'Worksheets("Projects").Cells(i, "C") = Worksheets("projects").Cells(r, "D") = Worksheets(i).Cells(e, "A").Value 'MONTHS Worksheets("Projects").Cells(r, "E") = Worksheets(i).Cells(e, "C").Value ' PROJECTS Worksheets("projects").Cells(r, "F") = Worksheets(i).Cells(e, "D").Value ' 1 Worksheets("Projects").Cells(r, "G") = Worksheets(i).Cells(e, "E").Value ' 2 Worksheets("Projects").Cells(r, "H") = Worksheets(i).Cells(e, "F").Value ' 3 Worksheets("Projects").Cells(r, "I") = Worksheets(i).Cells(e, "G").Value ' 4 Worksheets("Projects").Cells(r, "J") = Worksheets(i).Cells(e, "H").Value ' 5 Worksheets("Projects").Cells(r, "K") = Worksheets(i).Cells(e, "I").Value ' 6 Worksheets("Projects").Cells(r, "L") = Worksheets(i).Cells(e, "J").Value ' 7 Worksheets("Projects").Cells(r, "M") = Worksheets(i).Cells(e, "K").Value ' 8 Worksheets("Projects").Cells(r, "N") = Worksheets(i).Cells(e, "M").Value '9 Worksheets("Projects").Cells(r, "O") = Worksheets(i).Cells(e, "N").Value ' 10 Worksheets("Projects").Cells(r, "P") = Worksheets(i).Cells(e, "P").Value ' 10 Worksheets("Projects").Cells(r, "Q") = "=sum(RC5:RC15)" r = r + 1 End If e = e + 1 Loop Until e = 149 Next i End Sub
Thanks to everyone who attempted to understand the crazyness i was trying to describe lol. I appreciate it!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks