Hello I am trying to make a macro which will copy all the 200 values from Sheet1 from A1 until A2 , and will paste them in Sheet 2 but the paste operation should paste them differently in 2 columns and in 3 rows space, for example.
Sheet1(A1) => Sheet2(A1)
Sheet1(A2) => Sheet2(B1)
Sheet1(A3) => Sheet2(A5)
Sheet1(A4) => Sheet2(B5)
Sheet1(A5) => Sheet2(A9)
Sheet1(A6) => Sheet2(B9)
As you can see the interval is +3 cells. So far what I made is to copy individual cell, and need any help or suggestions how to make the copy process from above.
Sub CopySelection()
Dim xlSel As Excel.Range
Set xlSel = Excel.Application.Selection
For i = 0 To 200
xlSel.copy Excel.Application.Sheets("Sheet2").Range("A1")
Next i
End Sub
Any Help will be welcome.
You could do this:
Dim Destination_Row As Integer
Destination_Row = 1
For Origin_Row = 1 To 200 Step 2
Sheet2.Cells(Destination_Row, 1).Value = Sheet1.Cells(Origin_Row, 1).Value
Sheet2.Cells(Destination_Row, 2).Value = Sheet1.Cells(Origin_Row + 1, 1).Value
Destination_Row = Destination_Row + 4
Next
The Cells
property returns a Range
for the specified Row
and Column
. Every step of the For
loop adds 2 to get the value from Sheet1
and adds 4 to the Destination_Row
to paste the value on Sheet2
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.