Macros to copy alternate rows to anothersheet

Closed
sg - Apr 28, 2010 at 07:03 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Apr 28, 2010 at 08:27 AM

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

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 28, 2010 at 08:27 AM
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
0