Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
613 views
in Technique[技术] by (71.8m points)

Copy rows range from Sheet1 to Sheet2 in excel VBA

My excel data is feeding from other real time application source. My requirement is I want to copy range A1:M20 periodically from Sheet1 to Sheet2. In Sheet2 append new rows(not overwritten). Someone help me to do in excel VBA/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I got the answer after long search. Here it is.

Sub copyData()
    Sheets("Sheet1").Select
    lr = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
    Range("A2:F" & lr).Copy
    Sheets("Sheet2").Select
    lrTarget = Cells.Find("*", Cells(1, 1), xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
    Cells(lrTarget + 1, 1).Select
    ActiveSheet.Paste
    Columns("A:F").AutoFit
    Cells(1, 1).Select
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...