user15169505
user15169505

Reputation:

Copy and Pasting Columns through Arrays

Copy and pasting the columns A2:A and B2:A from Sheet1 to Sheet6 and my code is working fine.

when code paste the data it starts pasting form A1 and B1 i want to paste the data form A2 and B2 in Sheet6.

Dim ColumnAarray() As Variant
Dim my_Arange As Range
LastRow = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row
Set my_Arange = Sheet1.Range("A2:B" & LastRow)
ReDim ColumnAarray(LastRow)
ColumnAarray = my_Arange
For i = LBound(ColumnAarray) To UBound(ColumnAarray)
    Sheet6.Range("A" & i) = ColumnAarray(i, 1)
    Sheet6.Range("B" & i) = ColumnAarray(i, 2)
Next i

I just want to paste the data from row2.

Upvotes: 0

Views: 81

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57673

You don't need to loop to do that

Dim LastRow As Long
LastRow = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row

Dim ColumnAarray() As Variant
ColumnAarray = Sheet1.Range("A2:B" & LastRow).Value
Sheet6.Range("A2:B" & LastRow).Value = ColumnAarray

Actually you don't even need an array

Dim LastRow As Long
LastRow = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row

Sheet6.Range("A2:B" & LastRow).Value = Sheet1.Range("A2:B" & LastRow).Value

Upvotes: 2

Related Questions