Copy rows with data to another workbook

andysh

Board Regular
Joined
Nov 8, 2019
Messages
73
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
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,590
Office Version
365
Platform
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
35,590
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,089,394
Messages
5,407,990
Members
403,176
Latest member
mehtavish1

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top