Hello, I am trying to run a simple loop and am having trouble. I would like for this loop to run through the data in an excel spreadhseet and analize column "p". Upon analisys, the macro will create a new worksheet each time it encounters a new digit in coulmn "p". It will then take all rows (and content within) conatining that identifier and pull it to the new worksheet. The current code is running a loop that will stop each time the first new worksheet is created. The code is as follows. I see the errors in rows 9 - 11 but am unable to figure how to fix it. any and all help is appreciated.
Thank You ahead of time,
Sub copy_rows_to_sheets() Dim firstrow, lastrow, r, torow As Integer Dim fromsheet, tosheet As Worksheet firstrow = 1 Set fromsheet = ActiveSheet lastrow = ActiveSheet.Cells(Rows.Count, "P").End(xlUp).Row For r = firstrow To lastrow If fromsheet.Cells(r, "P") <> "" Then 'skip rows where column P is empty On Error GoTo make_new_sheet Set tosheet = Worksheets("" & fromsheet.Cells(r, "P")) On Error GoTo 0 GoTo copy_row make_new_sheet: Set tosheet = Worksheets.Add(After:=Worksheets(Worksheets.Count)) tosheet.Name = fromsheet.Cells(r, "P") copy_row: torow = tosheet.Cells.SpecialCells(xlCellTypeLastCell).Row + 1 fromsheet.Cells(r, 1).EntireRow.Copy tosheet.Cells(torow, 1).PasteSpecial Paste:=xlPasteValues End If Next r Application.CutCopyMode = False fromsheet.Activate End Sub