I am attempting to copy a range of cells until the last used row from another workbook that my main workbook has already opened and activated. The range needs to begin at C2 over to Column M and then until the first blank row.
The Code I have so far copies the right cell columns, but extends down past the used rows into blank rows. I've attached a screenshot. Pasting the copied cells into the main workbook is successful.
Workbooks.Open ("C:\Users\user\Documents\Maintenance Department\General\Equipment Documentation\Holding Furnace\Readings\Data Logs\Flow Sensor Monthly Alarm Log - Inductor.xlsx")
ThisWorkbook.Activate
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Workbooks("Flow Sensor Monthly Alarm Log - Inductor.xlsx").Worksheets("Sheet1").Range("C2:M2" & LastRow).Copy
ThisWorkbook.Sheets("Data").Range("C" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
LastRow = Workbooks("Flow Sensor Monthly Alarm Log - Inductor.xlsx").Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
– Scott CranerRange("C2:M2" & LastRow)
will return the wrong row, ifLastRow
is 6 then the range becomesRange("C2:M26")
and notRange("C2:M6")
You wantRange("C2:M" & LastRow)
– Scott Craner