PDA

View Full Version : [SOLVED] Run-time error '1004': Application-defined or object-defined error



rockybalboa
11-19-2014, 02:31 AM
Hi,

I am getting this error in the last line. Please help.


wb.Sheets("Final report").Range(Selection, Selection.End(xlDown)).Select
Row4 = wb.Sheets("Final report").Range(Selection, Selection.End(xlDown)).Rows.Count
Selection.Copy
wb.Sheets("Template").Select
Selection.PasteSpecial Paste:=xlPasteValues
wb.Sheets("Final report").Select
ActiveCell.Offset(0, 2).Select
Range(ActiveCell, Cells(ActiveCell.Row + Row4, ActiveCell.Column)).Copy

Thanks

p45cal
11-19-2014, 03:04 AM
Works here as long as:
1. wb is the currently active workbook
2. SelectRow4 has a carriage return inserted between the t and the R
3. Sheets("Final report") is active at the start of the code 's execution.
4. When the line:
Row4 = wb.Sheets("Final report").Range(Selection, Selection.End(xlDown)).Rows.Count
is executed, Row4 is not assigned a number that when added to activecell.row on the last line, the result exceeds the number of rows on the sheet. This would typically occur when there is nothing below the selection when Row4 is being assigned a value.

rockybalboa
11-19-2014, 04:09 AM
@p45cal (http://www.vbaexpress.com/forum/member.php?3494-p45cal) Thank you. worked :)