VBA copy and paste with dynamic ranges

meister

New Member
Joined
Mar 1, 2013
Messages
2
Hi

So I am trying to move data from one spreadsheet into another; I'm new to VBA and I need some help writing the code for this macro.



' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Sheets("Canada").Select
Range("F851:F887").Select
Selection.Copy
Sheets("Alberta").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
End Sub

What I need is to loop this, and the next time it selects from "Canada" the range changes so that it selects the
next 37 entries (for example the next one would be F888-F924) and so on...until it hits an empty cell.

I also need the macro to paste the next selection (F888-F924) into the sheet "Alberta" as normal except one row below the row it previously pasted data into.

Any help would be greatly appreciated!!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi, meister,
WELCOME to MrExcel!

This should be close to what you need. We don't know your skills and knowledge, but I hope you will take the time to analyse this, so you can learn and progress. Good luck!
Code:
Option Explicit
Sub test()
Dim LastRow As Long
Dim i As Long
Dim j As Long

j = 1
Application.ScreenUpdating = False

    With Sheets("Canada")
    LastRow = .Range("F" & Rows.Count).End(xlUp).Row
        For i = 851 To LastRow Step 37
        j = j + 1
        .Range("F" & i & ":F" & i + 36).Copy
        Sheets("Alberta").Range("A" & j).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
        Next i
    End With

Application.ScreenUpdating = True
End Sub
kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top