that_one_girl
New Member
- Joined
- Mar 22, 2017
- Messages
- 43
Hello,
Below is my code. I have a workbook with 3 sheets "ALL RECORDS, ACTIVE, ARCHIVE", and I am trying to get the VBA to move the rows in the ALL RECORDS sheet that have "CURRENET" in Column J to the ACTIVE sheet, and rows that have "ARCHIVE" in Column J to the ARCHIVED sheet.......I am getting an error
"Compile Error: For without Next"
Can anyone help?
Private Sub Workbook_Open()
Dim i, LastRow
LastRow = Sheets("ALL RECORDS").Range("A" & Rows.Count).End(xlUp).Row
Sheets("ACTIVE").Range("A2:L60869").ClearContents
Sheets("ARCHIVE").Range("A2:L60869").ClearContents
For i = 2 To LastRow
If Sheets("ALL RECORDS").Cells(i, "J").Value = "CURRENT" Then
Sheets("ALL RECORDS").Cells(i, "J").EntireRow.Copy Destination:=Sheets("ACTIVE").Range("A" & Rows.Count).End(xlUp).Offset(1)
ElseIf Sheets("ALL RECORDS").Cells(i, "J").Value = "ARCHIVE" Then
Sheets("ALL RECORDS").Cells(i, "J").EntireRow.Copy Destination:=Sheets("ARCHIVE").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
End Sub
Below is my code. I have a workbook with 3 sheets "ALL RECORDS, ACTIVE, ARCHIVE", and I am trying to get the VBA to move the rows in the ALL RECORDS sheet that have "CURRENET" in Column J to the ACTIVE sheet, and rows that have "ARCHIVE" in Column J to the ARCHIVED sheet.......I am getting an error
"Compile Error: For without Next"
Can anyone help?
Private Sub Workbook_Open()
Dim i, LastRow
LastRow = Sheets("ALL RECORDS").Range("A" & Rows.Count).End(xlUp).Row
Sheets("ACTIVE").Range("A2:L60869").ClearContents
Sheets("ARCHIVE").Range("A2:L60869").ClearContents
For i = 2 To LastRow
If Sheets("ALL RECORDS").Cells(i, "J").Value = "CURRENT" Then
Sheets("ALL RECORDS").Cells(i, "J").EntireRow.Copy Destination:=Sheets("ACTIVE").Range("A" & Rows.Count).End(xlUp).Offset(1)
ElseIf Sheets("ALL RECORDS").Cells(i, "J").Value = "ARCHIVE" Then
Sheets("ALL RECORDS").Cells(i, "J").EntireRow.Copy Destination:=Sheets("ARCHIVE").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
End Sub