Range in worksheet1 Insert into worksheet2 from row 2

dufusgoofus

New Member
Joined
Feb 25, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello. VBA noob here. Learning on-the-fly to solve an issue.

---------------
The Issue
---------------
  • Source workbook, wbSource, has worksheet wsSource
  • Destination workbook, wbDestination has worksheet wsDestination.
  • Macro takes new data from wsSource and puts it into wsDestination, whereupon all rows are sorted by date in descending order.
  • The code below works but the sorting in wsDestination takes time (there's a lot of data).
---------------
The Question
---------------
  • How can I insert row count from wsSource into wsDestination row 2 onwards?
    • Hoping that by adding blank rows in wsDestination will
      • allow me to continue using the method where values in destination range = values in source range.
      • eliminate need to sort dates in wsDestionation, and
      • reduce time taken for macro to run
    • Number of rows from wsSource varies.
---------------
Partial VBA
---------------
With wsSource
LastRow = .Cells(Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(Columns.Count).End(xlToLeft).Column
Set rgSource = .Range(.Cells(2, 1), .Cells(LastRow, LastCol))
End With
... ...
(open wbDestination)
Set rgDest = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
rgDest.Resize(rgSource.Rows.Count, rgSource.Columns.Count).Value = rgSource.Value
Range("A:H").Sort Key1:=[D2], Order1:=xlDescending, Header:=xlYes


Thanks.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You could try:
VBA Code:
insrtrw = wsSource.Rows.count 'to get the number of rows required to be inserted

'then in your destination sheet
Range("A2").Resize(insrtrw).Entirerow.Insert 'This will add blank rows equaling the number of rows you want to add then put your range here.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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