Macros to copy alternate rows to anothersheet [Closed]

Report
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-

Kindly tell me the macros to copy alternate rows to another sheet in excel

1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
763
Sub copyrow()
Dim lMaxRowsCopyFrom As Long
Dim lMaxRowCopyTo As Long
Dim lCopyRow As Long
Dim lStartRow As Long
Dim sCopyFrom As String
Dim sCopyTo As String
    
    lStartRow = 2
    sCopyTo = "Sheet2"
    sCopyFrom = "Sheet1"
    
    lMaxRowsCopyFrom = Sheets(sCopyFrom).Cells(Rows.Count, "A").End(xlUp).Row
    
    lMaxRowCopyTo = Sheets(sCopyTo).Cells(Rows.Count, "A").End(xlUp).Row
    If lMaxRowCopyTo = 1 Then lMaxRowCopyTo = 2
    
    For lCopyRow = lStartRow To lMaxRowsCopyFrom Step 2
    
        Sheets(sCopyTo).Range(lMaxRowCopyTo & ":" & lMaxRowCopyTo) = Sheets(sCopyFrom).Range(lCopyRow & ":" & lCopyRow).Value
        lMaxRowCopyTo = lMaxRowCopyTo + 1
    
    Next lCopyRow

End Sub

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!