tags:

views:

356

answers:

1
+1  Q: 

Excel VBA Macro

The List:- “Problem Sheet”(worksheet).

I have an excel sheet which represents a list of problem issues (Rows) which varies in size every day (eg more or fewer rows); Each row has been assigned a name; The assigned name is always in the same column “M” of the “Problem Sheet”; An individual assignment name does not necessarily appear every day, or it may occur several times (on more than one row) on a given day;

I already have a macro that creates a Unique List (worksheet) of assignment names where each name appearing in column M of the Problem Sheet is recorded once in the “Unique List” worksheet; The same macro creates a single new worksheet (in the same workbook) for every unique occurrence of an Assignment Name. The Assignment Name is recorded automatically in the new individual worksheet tab.

Required:- A macro that will check Column M of the main “Problem Sheet”; For every row / problem where a particular assignment name occurs in Column M of the Problem Sheet, Match the assignment name with the worksheet of the same name, then Copy and Paste the details of the entire row from the “Problem Sheet” to the first blank row of the correct (same assigned name) worksheet in the existing workbook. This routine must be repeated for every row in the Problem Sheet.

A: 

If order doesn't matter, this might be your best bet

Sub x()
    Dim rngProbs As Range
    With ThisWorkbook.Worksheets("Problem Sheet")
        Set rngProbs = .Range("M1", .Range("M1").End(xlDown))
    End With

    Dim r As Range


    For Each r In rngProbs
        r.EntireRow.Copy
        ThisWorkbook.Worksheets(r.Text).Rows(1).EntireRow.Insert
    Next r

End Sub
Ryan Shannon
Answer works perfectly, changed Rows(1) to Rows(2) to avoid title bar already in place in each sheet.