我希望将原来位于2列(x,y)中的单元格从工作表1复制到工作表2,并将其粘贴到工作表2中,因此无论x,y中的数据总数如何,它都具有以下格式列:
x y ////////////////// into
11 12 //////////////////// 11 12 21 22 31 32
21 22 //////////////////// 41 42 51 52 61 62
31 32 //////////////////// ... ...
41 42
51 52
61 62
… …
Sub CommandButton3_Click()
Dim ar As Integer
Dim al As Integer
Dim asp As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
ar = Range("A" & Rows.Count).End(xlUp).Row
al = ar - 6
asp = Round(al / 3)
i = 7 '(row number of first cell to copy)
j = 5 '(row number of pasted cell)
k = 2 '(column number of pasted cell)
For i = i To ar
For j = j To asp
Worksheets("XSections").Activate
Worksheets("XSections").Range(Cells(i, 1), Cells(i, 2), Cells(i + 1, 1), Cells(i + 1, 2), Cells(i + 2, 1), Cells(i + 2, 2)).Copy
Worksheets("Sorted").Activate
Worksheets("Sorted").Range(Cells(j, k), Cells(j, k + 1), Cells(j, k + 2), Cells(j, k + 3), Cells(j, k + 4), Cells(j, k + 5), Cells(j, k + 6)).Select
ActiveSheet.Paste
i = i + 3
Next j
Next i
End Sub
一旦我插入for函数,事情就会变得复杂并且没有输出。