I copied this code and made some changes to fit my needs.
It does what I want it to do as far as coping the rows over to a new sheet, but it won't clear the old data when the code is run.
Can someone show me why it doesn't work?
I am not very good with codes
Keith
Sub CopyRowToPenders()
'========================================================================
' COPIES ALL ROWS WHERE COLUMN AH HAS VALUE "P/IHF" FROM March 2011
' INTO "Penders" SHEET
'========================================================================
Dim LastRowMarch2011, LastRowPenders As Long
Dim i As Long
Application.ScreenUpdating = False
' LastRowPenders = Worksheets("Penders").Range("A" & Rows.Count).End(xlUp).Row
' Sheets("Penders").Range("A2:AM" & LastRowPenders).ClearContents
LastRowMarch2011 = Worksheets("March 2011").Range("A" & Rows.Count).End(xlUp).Row
With Worksheets("March 2011")
For i = 2 To LastRowMarch2011 Step 1
If Cells(i, "AH").Value = "P/IHF" Then
LastRowPenders = Worksheets("Penders").Range("A" & Rows.Count).End(xlUp).Row
Rows(i).Copy Worksheets("Penders").Range("A" & LastRowPenders + 1)
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
It does what I want it to do as far as coping the rows over to a new sheet, but it won't clear the old data when the code is run.
Can someone show me why it doesn't work?
I am not very good with codes
Keith
Sub CopyRowToPenders()
'========================================================================
' COPIES ALL ROWS WHERE COLUMN AH HAS VALUE "P/IHF" FROM March 2011
' INTO "Penders" SHEET
'========================================================================
Dim LastRowMarch2011, LastRowPenders As Long
Dim i As Long
Application.ScreenUpdating = False
' LastRowPenders = Worksheets("Penders").Range("A" & Rows.Count).End(xlUp).Row
' Sheets("Penders").Range("A2:AM" & LastRowPenders).ClearContents
LastRowMarch2011 = Worksheets("March 2011").Range("A" & Rows.Count).End(xlUp).Row
With Worksheets("March 2011")
For i = 2 To LastRowMarch2011 Step 1
If Cells(i, "AH").Value = "P/IHF" Then
LastRowPenders = Worksheets("Penders").Range("A" & Rows.Count).End(xlUp).Row
Rows(i).Copy Worksheets("Penders").Range("A" & LastRowPenders + 1)
End If
Next i
End With
Application.ScreenUpdating = True
End Sub