Copy rows with data to another workbook

andysh

Board Regular
Joined
Nov 8, 2019
Messages
105
Hi

I have the below code to copy rows with data from one workbook to another ignoring the first two rows as these are header rows however it is only copying column 1. Where am I going wrong?

Sub Export_data()

Dim ws As Worksheet, wb As Worksheet

Set ws = Sheets("Triage")
Set wb = Workbooks("2019 - Couriersheet -copy.xlsx").Worksheets("Triage2")
Dim lr As Long, lrw As Long, lc As Long

Application.ScreenUpdating = False
Application.EnableEvents = False

lrw = ws.Range("A" &Rows.Count).End(xlUp).Row

If lrw > 2 Then

lc= ws.Cells(1, Columns.Count).End(xlToLeft).Column
lr = wb.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range(ws.Cells(3, 1), ws.Cells(lrw, lc)).Copy
wb.Range("A" & lr).PasteSpecial xlPasteValues
ws.Range(ws.Cells(3, 1), ws.Cells(lrw, lc)).EntireRow.Delete

End If


Application.CutCopyMode = False

Workbooks("Job Sheet WIP - copy").Save
Workbooks("2019 - Couriersheet -copy.xlsx").Save

Application.ScreenUpdating = True
Application.EnableEvents = True

MsgBox" Exported ! "


End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows
Change this line
Code:
ws.Range(ws.Cells(3, 1), ws.Cells(lrw, lc)).Copy
to
Code:
ws.Rows("3:" & lrw).Copy
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,468
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,129,383
Messages
5,635,942
Members
416,889
Latest member
dhegs

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
Top