[英]How to Copy Range And Paste in 1 Column
Anyone Have Some Idea to make something like this with VBA in Excel . 任何人都有一些想法可以在Excel中使用VBA进行类似的操作。 Please...
请...
Range (D2 : M4)
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
to be pasted just on 1 column B or Range (B3 : B33) like below: 粘贴到下面的1列B或范围(B3:B33)上:
1
2
3
4
5
6
7
....etc
30
Try with below code. 尝试下面的代码。 It will work
会工作的
Sub test()
Dim i As Long
For i = 2 To 4
If i = 2 Then
Sheets("Sheet3").Range("D" & i, "M" & i).Copy
Sheets("Sheet3").Range("B3").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
Else
Sheets("Sheet3").Range("D" & i, "M" & i).Copy
Sheets("Sheet3").Range("B" & Sheets("Sheet3").Range("B" & Rows.Count).End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End If
Next i
End Sub
if you need to paste only values 如果只需要粘贴值
Sub main()
Dim i As Long
Dim cell As Range
For Each cell In Range("D2:M4")
Range("B3").Offset(i).Value = cell.Value
i = i + 1
Next cell
End Sub
if you need to paste "all" cell 如果您需要粘贴“所有”单元格
Sub main()
Dim i As Long
Dim cell As Range
For Each cell In Range("D2:M4")
cell.Copy Destination:=Range("B3").Offset(i)
i = i + 1
Next cell
End Sub
I see you have an accepted answer, but here is an alternative solution using formula TRANSPOSE : 我看到您有一个可接受的答案,但这是使用公式TRANSPOSE的替代解决方案:
Sub TransposeData()
Dim Data As Range, iRow&, RowData&, ColData&
Set Data = Worksheets("Sheet1").Range("D2:M4")
RowData = Data.Rows.Count: ColData = Data.Columns.Count
For iRow = 1 To RowData
Range("B" & 3 + (iRow - 1) * ColData).Resize(ColData, 1) = WorksheetFunction.Transpose(Data.Rows(iRow))
Next
End Sub
Note that it only copy-paste the value, its format's excluded. 请注意,它仅复制粘贴值,不包括其格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.