PDA

View Full Version : Solved: Last Row, CopyPaste



vzachin
09-23-2008, 10:44 AM
hi,

i'm copy data from sheet1 to sheet2
i'm having problem with defining a lastrow because all the cells in the range contains a formula.
when i define the last row here:iLastRw = Sheets("sheet1").Cells(endrw, "e").End(xlUp).Row
the last row is picking up the formulas in that row.
i only want to copy the rows (from column e to column j) with data in them. the rows of data will be consecutive (in other words, the rows of data will never skip).
i experience problems when i do a subsequent copy & paste in sheet2. i want to paste to the last active row +1 in sheet2 but the initial copy & paste, pasted all the rows from sheet 1.

is there a way around this?

i have to do multiple copy & paste, which is why i'm defining my rows.

here's my coding so far
Sub test1()
begrw = 13
endrw = 31
iLastRw = Sheets("sheet1").Cells(endrw, "e").End(xlUp).Row
LastRw = Sheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Row
Range(("F" & begrw), ("J" & iLastRw)).Copy
Sheets("sheet2").Range("a" & LastRw + 1).PasteSpecial xlValues
Application.CutCopyMode = False
End Sub

i suppose i can write code to remove the empty rows in sheet2

thanks
zach

david000
09-24-2008, 09:28 AM
Sub test1()
With Sheet1

.Range("e13").Resize(.Cells(.Rows.Count, "e").End(xlUp).Row - 12, 5).Copy

With Sheet2

.Range("a3").PasteSpecial xlPasteValues

End With

End With

Application.CutCopyMode = False

End Sub

vzachin
09-28-2008, 06:09 PM
hi david000,
thanks.
here's my final coding with slight modification. the TextToColumns resolved the issues with pasting to the last active row

With Sheet2
.Range("A2:A200").TextToColumns Destination:=Range("A2"), DataType:=xlFixedWidth, _
FieldInfo:=Array(0, 1), TrailingMinusNumbers:=True
With Sheet1
.Range("e13").Resize(.Cells(.Rows.Count, "e").End(xlUp).Row - 12, 5).Copy

With Sheet2
rw = Sheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Row
rw = rw + 1
.Range("a" & rw).PasteSpecial xlPasteValues

End With
End With
End With

Application.CutCopyMode = False


thanks again
zach