Link to home
Start Free TrialLog in
Avatar of Jagwarman
Jagwarman

asked on

copy range to another sheet problem

I have been using the below to copy data from one sheet to another but in my current spreadsheet it is not only copying the data in the range but is going right to the end of the spreadsheet. i.e. my range might be AG2 – AL40 but it copies from AG2 – AL1048576

Obviously the range will change daily so it will be AG2 – AL??

Sheets("Turnover").Range(Range("AG2"), Cells.SpecialCells(xlCellTypeLastCell)).Copy
Sheets("Consolidated").Range("D" & Cells.Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues

Can an expert assist me on this please
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jagwarman
Jagwarman

ASKER

Brilliant many thanks. Both equal But I am forced to select one as Best.
It looks like your used range has got messed up. This can happen for a number of reasons but is usually easily solved.

The above amendments to your code will ensure the correct area is copied but it is still worth clearing the Used Range setting otherwise it could affect file size and performance.

On the sheet where you are encountering the issue press End then Home. The cursor should go to the last cell, ie bottom right of the data. If it goes to row 1048576 or beyond the row expected that shows the used range is corrupt (strong word but not drastic really).

Manually put the cursor in column A and the row below where the data ends. Press and hold Shift and press End then Home. This will highlight the surplus rows below the data. Remove those rows by right clicking and choose Delete, select Option for Delete Entire row and click OK. Go back to the top of the sheet, Save and Close the file. Re-open and test to see if End then Home now goes to the last expected row.

Thanks
Rob H