使用VBA在excel中复制几个值并将其粘贴到同一行中多次 [英] copying few values in a row and pasting it multiple times in the same row in excel using VBA
问题描述
Sub Macro1()
/ pre>
范围(a1)。选择
Selection.Copy
范围(a2:a30)。选择
ActiveSheet.Paste
End Sub
如果我有多个值,我该怎么办?
Sub Macro1()
范围(a1:a24)。选择
Selection.Copy
现在我需要将上述24个值粘贴到(A25:A8760)上吗?
感谢解决方案起初我以为这样:
Range(A1:A24) .Copy Range(A25:A8760)
或Range(A25:A8760)Value = Range(A1:A24)。值
应该工作。但是,由于上述解决方案仅在已使用部分中复制,所以不会。
然后我想出以下解决方案(仅复制值):
With Range(A25:A8760)
pre>
.Formula == A1
.Value = .Value
结束
UPD:
此代码适用:
范围(A25:A8760)Value =
范围(A1:A24)复制范围(A25: A8760)
注意:
我使用
Range(A25:A8760)。Value =
使此范围成为UsedRange
(否则行范围(A1:A24)。复制范围(A25:A8760)
只会在used表单)I am very new to VBA.I know its a basic doubt but couldnt find the solution anywhere. I am trying to copy 24 (A1:A24)values and paste it number of times in (A25:A8760).I am able to copy a single value and paste it number of times.I couldnt do it for multiple values.
Sub Macro1() Range("a1").Select Selection.Copy Range("a2:a30").Select ActiveSheet.Paste End Sub
How do i do it if i multiple values?
Sub Macro1() Range("a1:a24").Select Selection.Copy
Now i need to paste the above 24 values to (A25:A8760) continously? Thanks
解决方案At first I thought this:
Range("A1:A24").Copy Range("A25:A8760")
orRange("A25:A8760").Value = Range("A1:A24").Value
should work. However it doesn't, because above solutions copy only in "used" part of the sheet.Then I come up with following solution (copies only values):
With Range("A25:A8760") .Formula = "=A1" .Value = .Value End With
UPD:
this code works:
Range("A25:A8760").Value = "" Range("A1:A24").Copy Range("A25:A8760")
Notes:
I used
Range("A25:A8760").Value = ""
to make this range to be part ofUsedRange
(otherwise lineRange("A1:A24").Copy Range("A25:A8760")
would copy only in "used" part of the sheet)这篇关于使用VBA在excel中复制几个值并将其粘贴到同一行中多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!