Copy rows with data to another workbook

andysh

New Member
Joined
Nov 8, 2019
Messages
34
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
 

Fluff

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

Forum statistics

Threads
1,078,437
Messages
5,340,278
Members
399,362
Latest member
iayb

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top