views:

408

answers:

2

I have an excel workbook that is used to track tasks by project. Each project has its own worksheet in the workbook.

Within each worksheet, there are rows for each work item, and the first column contains the person's name that the work item is assigned to. These rows are not sorted by name.

I want to create a worksheet that will automatically go through each of the worksheets (other than the active sheet) and pull in all rows assigned to a certain person.

Anyone know of a VBA Macro that will take care of this for me?

+1  A: 

This should get you started:

Option Explicit

'// change this name to generate a report for a different user //'
Const activeUser = "Alex"

'// change these values to fit your data //'
Const maxTasks = 100
Const maxCols = 10

Public Sub BuildSummary()
    Dim projectIndex As Integer
    Dim projectSheet As Worksheet
    Dim taskIndex As Integer
    Dim summaryRow As Integer

    summaryRow = 1
    For projectIndex = 1 To ActiveWorkbook.Worksheets.Count
        Set projectSheet = ActiveWorkbook.Worksheets(projectIndex)
        If projectSheet.Index <> ActiveSheet.Index Then

            '// insert a row with the name of the project //'
            ActiveSheet.Cells(summaryRow, 1).Value = projectSheet.Name
            summaryRow = summaryRow + 1

            '// search for the active user in each task //'
            For taskIndex = 1 To maxTasks
                If projectSheet.Cells(taskIndex, 2).Value = activeUser Then

                    '// copy the relevant rows to the summary sheet //'
                    projectSheet.Range(projectSheet.Cells(taskIndex, 1), _
                        projectSheet.Cells(taskIndex, maxCols)).Copy
                    ActiveSheet.Range(ActiveSheet.Cells(summaryRow, 1), _
                        ActiveSheet.Cells(summaryRow, maxCols)).Select
                    ActiveSheet.Paste
                    summaryRow = summaryRow + 1
                End If
            Next taskIndex
        End If
    Next projectIndex

    ActiveSheet.Cells(1, 1).Select
End Sub
e.James
With some very slight adjustments, this did exactly what I was looking for.Thanks for putting this together!
Matt
No problem. I'm glad to hear it was useful!
e.James
A: 

Worksheet 1 contains 2 x columns - A=Team and B=Name Worksheet 2 contains 10 columns. Name is located in column H.

I need to compare Column H of worksheet 2 with column B of worksheet 1. When it locates it's match in worksheet 1 I need it to look at column A and populate the row from Worksheet B into worksheet C titled after Column A in a third worksheet

Can't use V-look up as the names appear multiple times in worksheet 2 and I need all lines pulled into the new worksheet.

Suggestions?

Tiffaney