Excel - Copy a selected range

Post Reply
wwj
Posts: 2497
Joined: 27 Jan 2007 08:16

Excel - Copy a selected range

Post by wwj »

1. Copy a known range.

Code: Select all

    Sheets(outSheet).Range("A1:k3").Value = Sheets(inputSheet).Range("A1:k3").Value
2. Copy a variable range.

Code: Select all


    Sheets(outSheet).Range("A1:k3").Value = Sheets(inputSheet).Range("A1:k3").Value
    totalRow = Sheets(inputSheet).Cells(Rows.Count, "A").End(xlUp).Row
    swCopy = True
    i = 4
    While (swCopy And i < totalRow)
        tm = Sheets(inputSheet).Cells(i, "A")
        If tm > 116800 Then                     ' End of SS & Pseudo-SS periods (End of 1984)
            With Worksheets(inputSheet)
                .Range(.Cells(i, "A"), .Cells(totalRow, "K")).Copy _
                Destination:=Worksheets(outSheet).Range("A4")
            End With
            
            swCopy = False
            i = totalRow
        End If
        
        i = i + 1
    Wend
    
Post Reply