To copy an entire row in Excel VBA, you can use the “EntireRow” property along with the “Copy” method. Here is an example:
Sub CopyRow()
Dim sourceRow As Range
Dim destinationRow As Range
' Set the source row
Set sourceRow = Range("A1").EntireRow
' Determine the destination row (e.g., one row below)
Set destinationRow = sourceRow.Offset(1)
' Copy the source row to the destination row
sourceRow.Copy destinationRow
End Sub
In the above example, the “CopyRow” subroutine copies the entire row starting from cell A1 to the row below it. Here’s a breakdown of the code:
- We declare two Range variables, “sourceRow” and “destinationRow”, to store the references to the source row and the destination row, respectively.
- We set the source row using the “EntireRow” property of a range. In this example, we selected cell A1 and obtained its entire row.
- We determine the destination row by offsetting the source row by one row below. You can customize the offset as needed.
- We use the “Copy” method to copy the source row to the destination row. This method is available on the Range object.
By running the “CopyRow” subroutine, the source row will be duplicated below, effectively copying the entire row.