• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

copy and paste rows from one sheet to another(Excel)

Hi ,

I am looking for a MACRO to copy data from "sheet1" to the next available row on "sheet2".

excel sample attached.

Thanks very much
Book1.xlsm
0
shamilaz
Asked:
shamilaz
  • 2
  • 2
1 Solution
 
Saqib Husain, SyedEngineerCommented:
Uncomment one of the commented rows.
The first one will copy only row 3.
The second one will copy row 3 down to the last available rows.

Sub copyrows()
Dim sws As Worksheet
Dim tws As Worksheet
Set sws = Sheets("sheet1")
Set tws = Sheets("sheet2")
'sws.Range("A3").EntireRow.Copy tws.Range("A" & Rows.Count).End(xlUp).Offset(1)
'sws.Range("A3:A" & sws.Range("A" & Rows.Count).End(xlUp).Row).EntireRow.Copy tws.Range("A" & Rows.Count).End(xlUp).Offset(1)
End Sub

Open in new window

0
 
shamilazAuthor Commented:
Sorry forgot to mention one more thing....the copy and paste should be as a "value" only.....so that any links and formulas from the source doc will be disabled after the paste.  Appreciate if you could kindly amend to reflect this please
0
 
Saqib Husain, SyedEngineerCommented:
Sub copyrows()
Dim sws As Worksheet
Dim tws As Worksheet
Dim sr As Range
Set sws = Sheets("sheet1")
Set tws = Sheets("sheet2")
Set sr = sws.Range("A3:A" & sws.Range("A" & Rows.Count).End(xlUp).Row)
If sws.Range("A3") <> "" Then
    tws.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize( _
        sr.Rows.Count).EntireRow.Value = sr.EntireRow.Value
End If
End Sub
0
 
shamilazAuthor Commented:
Perfect ...the macro works as expected...great....thanks very much :-)
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now