Excel VBA Copy & Insert Cells Range

ekfasy

New Member
Joined
May 16, 2016
Messages
11
Hello,

I currently have VBA coding that is copying a variable range from one excel spreadsheet and pasting it into another.

Below is the code:

Code:
Sub MoveData()    Dim wb1 As Workbook, wb2 As Workbook
    Dim lr As Long
    Set wb1 = Workbooks("Copy of XYZ-ABCQuote-Testing") ' Change the name to match your workbook.
    Set wb2 = Workbooks("ABC-Quote To Customer-Testing") ' Change the name to match your workbook.
    With wb1.Worksheets("Quote") 'Change the name to match your worksheet.
        lr = .Cells(.Rows.Count, "A").End(xlUp).Row
        .Range(.Cells(21, 1), .Cells(lr, 1)).Copy _
        Destination:=wb2.Worksheets("ABC Quote").Range("C24") 'Change the name to match your worksheet.
        
        lr = .Cells(.Rows.Count, "B").End(xlUp).Row
        .Range(.Cells(21, 2), .Cells(lr, 2)).Copy _
        Destination:=wb2.Worksheets("ABC Quote").Range("D24") 'Change the name to match your worksheet.
        
        lr = .Cells(.Rows.Count, "C").End(xlUp).Row
        .Range(.Cells(21, 3), .Cells(lr, 3)).Copy _
        Destination:=wb2.Worksheets("ABC Quote").Range("B24") 'Change the name to match your worksheet.
        
        lr = .Cells(.Rows.Count, "D").End(xlUp).Row
        .Range(.Cells(21, 4), .Cells(lr, 4)).Copy _
        Destination:=wb2.Worksheets("ABC Quote").Range("E24") 'Change the name to match your worksheet.
        
        lr = .Cells(.Rows.Count, "E").End(xlUp).Row
        .Range(.Cells(21, 5), .Cells(lr, 5)).Copy _
        Destination:=wb2.Worksheets("ABC Quote").Range("F24") 'Change the name to match your worksheet.
        
    End With
     
End Sub

Does anyone know if it is possible to not just copy and paste these cells from wbk1 into wbk2, but instead to copy the cells from wbk1 and insert rows for those cells into wbk2. The number of rows will vary each time I run this macro, so it's important that the range it's being pasted into can be variable in the number of rows as well.

Any advice would be much appreciated!!!

Thanks :)
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You should post the links to the other forums, so every forum know it's posted on another forum.
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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