copy and paste macro help.

steve400243

Active Member
Joined
Sep 15, 2016
Messages
429
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello, I use this macro to copy and Paste from WS1 to WS2. But I need it to copy and paste new data on the next row down on Ws2 When the button is selected. I cant figure this out. Thanks for all help provided.

Code:
Sub ButtonCode()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim DestRow As Long
    Set ws1 = Sheets("Cartage Rate")
    Set ws2 = Sheets("Complete")
    DestRow = ws2.Cells(Rows.Count, "A").End(xlUp).Row + 1
    ws1.Range("B3").Copy ws2.Range("B" & DestRow)
    ws1.Range("C3").Copy ws2.Range("C" & DestRow)
    ws1.Range("D3").Copy ws2.Range("D" & DestRow)
    ws1.Range("E3").Copy ws2.Range("E" & DestRow)
    ws1.Range("F3").Copy ws2.Range("F" & DestRow)
    ws1.Range("D19").Copy ws2.Range("G" & DestRow)
    ws1.Range("E19").Copy ws2.Range("H" & DestRow)
    ws1.Range("F19").Copy ws2.Range("I" & DestRow)
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Change this:
Code:
DestRow = ws2.Cells(Rows.Count, "A").End(xlUp).Row + 1
To this
Code:
DestRow = ws2.Cells(Rows.Count, "B").End(xlUp).Row + 1
 
Last edited:
Upvote 0
Your not copying anything into column A on sheet2 but your using column A looking for data in lastrow

Why are you doing that?
 
Upvote 0
Change this:
Code:
DestRow = ws2.Cells(Rows.Count, "A").End(xlUp).Row + 1
To this
Code:
DestRow = ws2.Cells(Rows.Count, "B").End(xlUp).Row + 1

I looked at this 3 times and couldn't figure out why it wasn't doing it. Didn't realize the OP wasn't putting anything in "A".
 
Upvote 0
You could write your script like this:
Code:
Sub ButtonCode()
    'Modified  11/27/2018  8:26:42 PM  EST
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim DestRow As Long
    Set ws1 = Sheets("Cartage Rate")
    Set ws2 = Sheets("Complete")
    DestRow = ws2.Cells(Rows.Count, "B").End(xlUp).Row + 1
    ws1.Range("B3:F3").Copy ws2.Range("B" & DestRow)
    ws1.Range("D19:F19").Copy ws2.Range("G" & DestRow)
    End Sub
 
Upvote 0
You could write your script like this:
Code:
Sub ButtonCode()
    'Modified  11/27/2018  8:26:42 PM  EST
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim DestRow As Long
    Set ws1 = Sheets("Cartage Rate")
    Set ws2 = Sheets("Complete")
    DestRow = ws2.Cells(Rows.Count, "B").End(xlUp).Row + 1
    ws1.Range("B3:F3").Copy ws2.Range("B" & DestRow)
    ws1.Range("D19:F19").Copy ws2.Range("G" & DestRow)
    End Sub

Thanks My Answer - This works great as well. I appreciate your time in looking at it. F19 Is a sum total, and when it copies over I loose the amount? Any ideas?

Code:
=SUM(F13+F15+F17-E19)
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top