Help in Writing VBA Macro excel

Closed
learningmacro Posts 1 Registration date Thursday 25 October 2012 Status Member Last seen 25 October 2012 - 25 Oct 2012 à 10:37
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 30 Oct 2012 à 10:56
Hello,

I wish to write a macro for following:

1. Delete entire rows if column L or column M contain DATE.
2. Move deleted entire rows to other sheet in same workbook.

Thanks.
Related:

1 response

TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 555
30 Oct 2012 à 10:56
Hi Learningmacro,

I assumed the following:
Columns L and M has the same amount of data.
Column A always contains data.

Here you go:
Sub MoveAndDelete()
Dim lRow, faRow, x As Integer

lRow = Sheets("Sheet1").Range("M" & Rows.Count).End(xlUp).Row

For Each cell In Sheets("Sheet1").Range("L1:M" & lRow)
    If cell.Value = "DATE" Then
        faRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row
        cell.EntireRow.Copy Sheets("Sheet2").Range("A" & faRow)
        cell.EntireRow.ClearContents
    End If
Next cell

For x = lRow To 1 Step -1
    If Range("A" & x) = vbNullString Then Range("A" & x).EntireRow.Delete
Next x

End Sub

Best regards,
Trowa