【发布时间】:2019-02-06 04:10:10
【问题描述】:
输入数据始终是 7 个不同工作表中的列,需要在不同的非顺序行中的不同列中输出
Q2_1 Q3_1 Q4_1
13 17 11
4 2 5
3 2 4
2 2 4
6 5 4
行(输出)的顺序是 5, 10, 15, 23, 28, 33, 38, 43, 48, 53, 61, 66, 71, 79, 84, 89, 94, 102, 107, 112、117、122、128、135、140、148、153、158、166、171、179、184、189、194
Q2_1 的列从 i5 到 M5,Q3 的列从 i10 到 M10
我尝试了 2 个 fors 和 2 个 do 循环,但没有成功。有没有办法使用数组?
我非常喜欢编程。
Sub CPRelative()
Dim n As Integer
Dim i As Integer
Dim itotal As Integer
Windows("book1.xlsx").Activate
Sheets(3).Select
For n = 2 To 35
ActiveSheet.Range(Cells(4, n), Cells(8, n)).Select
Selection.Copy
Windows("book2.xlsm").Activate
For i = 5 To 194
Select Case i
Case 5, 10, 15, 23, 28, 33, 38, 43, 48, 53, 61, 66, 71, 79, 84, 89, 94, 102, 107, 112, 117, 122, 128, 135, 140, 148, 153, 158, 166, 171, 179, 184, 189, 194
ActiveSheet.Range(Cells(i, 9), Cells(i, 13)).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End Select
Next n
End Sub
直到和同时做
Sub NestedLoop()
Dim n As Integer
Dim i As Integer
Windows("book1.xlsx").Activate
Sheets(3).Select
n = 2
Do Until ActiveSheet.Range(Cells(4, n), Cells(8, n)).Value = ("8,n")
ActiveSheet.Range(Cells(4, n), Cells(8, n)).Select
Selection.Copy
Windows("book2.xlsm").Activate
Sheets(1).Select
'i = 5
Do While ActiveSheet.Range(Cells(i, 9), Cells(i, 13)).Value = ""
Select Case i
Case 5, 10, 15, 23, 28, 33, 38, 43, 48, 53, 61, 66, 71, 79, 84, 89, 94, 102, 107, 112, 117, 122, 128, 135, 140, 148, 153, 158, 166, 171, 179, 184, 189, 194
ActiveSheet.Range(Cells(i, 9), Cells(i, 13)).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End Select
i = i + 1
Loop
n = n + 1
Loop
End Sub
【问题讨论】:
-
"有没有办法使用数组?"是的,you can use arrays 和 here's how you transpose them
标签: excel vba copy-paste