copying few values in a row and pasting it multipl

2019-08-01 13:47发布

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

2条回答
地球回转人心会变
2楼-- · 2019-08-01 13:55

The following will copy and past 364 times...

Sub Macro1()
Dim i As Integer

Range("A1:A24").Select
Selection.Copy
For i = 1 To 364
    Range("A" & 1 + i * 24).Select
    ActiveSheet.Paste
Next i
End Sub
查看更多
戒情不戒烟
3楼-- · 2019-08-01 14:14

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)

查看更多
登录 后发表回答