使用VBA在excel中复制几个值并将其粘贴到同一行中多次 [英] copying few values in a row and pasting it multiple times in the same row in excel using VBA

查看:421
本文介绍了使用VBA在excel中复制几个值并将其粘贴到同一行中多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对VBA很新,我知道这是一个基本的疑问,但是无法找到解决方案。我试图复制24(A1:A24)值并将其粘贴次数(A25:A8760)。我可以复制一个值并粘贴次数。我不能为多个值。

  Sub Macro1()

范围(a1)。选择
Selection.Copy

范围(a2:a30)。选择

ActiveSheet.Paste

End Sub
/ pre>

如果我有多个值,我该怎么办?

  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)
.Formula == A1
.Value = .Value
结束
pre>

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") or Range("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 of UsedRange (otherwise line Range("A1:A24").Copy Range("A25:A8760") would copy only in "used" part of the sheet)

这篇关于使用VBA在excel中复制几个值并将其粘贴到同一行中多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆