简体   繁体   中英

Copy and paste a range of cell values into another sheet with VBA and using Offset

I want to copy and paste values from one sheet to another via button assigned to a macro. And every time I hit the button the pasted values should skip some rows so it doesn't paste on the previous values. Below is my code so far, the problem is that the loop never stops. There is probably a better way? maybe a loop isn't the way to do it?

Please post the answer in code if you know, or give me some tips. I would really appreciate it.

Sub Savestrategy()

Dim Bookmark As Integer
Dim positioner As Integer

For Each cell In Range("A2:L20")

    Worksheets("Dashboard").Range("Bookmark").Copy

    Worksheets("Bookmarks").Range("A2").Offset(positioner, 0).PasteSpecial Paste:=xlPasteFormats
    Worksheets("Bookmarks").Range("A2").Offset(positioner, 0).PasteSpecial Paste:=xlPasteValues

    positioner = positioner + 20

    Application.CutCopyMode = False

Next cell

End Sub

Why are you looping? You are not even using the range to loop.

Not tested but you can see where i am going with it. If i knew the range of "Bookmark." I could help you further.

Worksheets("Bookmarks").Range("A2:L20").Offset(20, 0).value = Worksheets("Dashboard").Range(Bookmark).value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM