I'm a newbie and trying to create a macro but just cannot figure out why I keep receiving this compile error. I thought this code was fairly straightforward. Can someone please help me troubleshoot? Thanks!
Code:
Sub Copy_Incompletes() '
'
'
Dim i, Totrows As Integer
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("CA-Alta")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("CA-Jefferson")
Dim ws3 As Worksheet: Set ws3 = ThisWorkbook.Sheets("CA-Sheridan")
Dim ws4 As Worksheet: Set ws4 = ThisWorkbook.Sheets("CA-Reedley")
Dim ws5 As Worksheet: Set ws5 = ThisWorkbook.Sheets("CA-Incompletes")
Application.ScreenUpdating = False
ws1.Activate
Totrows = Range(Cells(3, 1), Cells(3, 1).End(xlDown).Address).Rows.Count + 2
For i = 3 To Totrows
If Cells(i, 1) = "Incomplete" Then Rows(i).Copy
'activates CA-Incompletes worksheet
ws5.Activate
Rows(3).Select
Selection.Insert Shift:=xlDown
ws1.Activate
'Copy row and paste it to the other worksheet
End If
Next i
ws2.Activate
Totrows = Range(Cells(3, 1), Cells(3, 1).End(xlDown).Address).Rows.Count + 2
For i = 3 To Totrows
If Cells(i, 1) = "Incomplete" Then Rows(i).Copy
'activates CA-Incompletes worksheet
ws5.Activate
Rows(3).Select
Selection.Insert Shift:=xlDown
ws2.Activate
'Copy row and paste it to the other worksheet
End If
Next i
ws3.Activate
Totrows = Range(Cells(3, 1), Cells(3, 1).End(xlDown).Address).Rows.Count + 2
For i = 3 To Totrows
If Cells(i, 1) = "Incomplete" Then Rows(i).Copy
'activates CA-Incompletes worksheet
ws5.Activate
Rows(3).Select
Selection.Insert Shift:=xlDown
ws3.Activate
'Copy row and paste it to the other worksheet
End If
Next i
ws4.Activate
Totrows = Range(Cells(3, 1), Cells(3, 1).End(xlDown).Address).Rows.Count + 2
For i = 3 To Totrows
If Cells(i, 1) = "Incomplete" Then Rows(i).Copy
'activates CA-Incompletes worksheet
ws5.Activate
Rows(3).Select
Selection.Insert Shift:=xlDown
ws4.Activate
'Copy row and paste it to the other worksheet
End If
Next i
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: