Macro to copy last row in range

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I add my sales into sheet "Quotes" Range is D27:O51

The data for each sale is two rows,
row1 the details,
row2 Notes, (Not all sales have notes)

so what I want is a macro that will copy the last "Row1" sales details and paste it below but it needs to place it 2 rows down to miss the notes row.

So if the last row was 29, it would copy and paste into row 31 etc.
now to complicate things more, I only want to copy columns D to K and O

I've attached a table to try show what my sheet looks like. Please help if you can thanks Tony

CDEFGHIJKLMNOPQ
26PartTypenumberPriceQantsold%datecountryareatimePerson
27Details:A1R12221Y1002018UKNW12TW
28Notes:this rowdoes not count asthe last row andisnot copied
29Details:S3E11221Y1002017USANNT11TW
30Notes:
31Details:D2Q111112N1002016UKNW1TW
32Notes:
33Details:P9P9999Y992018UKN2TWOK, so this is the last detals row so this would be copied
34Notes:THERE MIGHT BENOTESHERE IT MIGHT BE BLANK
35Details:copiedrowwouldgohere
36Notes:
37Details:
38Notes:
39

<tbody>
</tbody>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Find the 1st empty row in column d and see what is beside it, if it is "Notes:" then use the row below.

Code:
Sub Button1_Click()
    Dim LstRw As Long, r As Range
    
    LstRw = Cells(Rows.Count, "D").End(xlUp).Row + 1
    
    If Range("C" & LstRw) = "Notes:" Then LstRw = LstRw + 1
    
    Set r = Range("D" & LstRw & ":K" & LstRw + 1, "O" & LstRw & ":O" & LstRw + 1)
    
    r = "=IF(R[-2]C="""","""",R[-2]C)"
    r.Value = r.Value

End Sub
 
Upvote 0
How about
Code:
Sub GetLastDetails()
   Dim Fnd As Range
   
   Set Fnd = Range("D" & Rows.Count).End(xlUp)
   If Fnd.Offset(, -1).Value <> "Details:" Then Set Fnd = Fnd.Offset(-1)
   Fnd.Resize(, 12).Copy Fnd.Offset(2)
   Fnd.Offset(2, 8).Resize(, 3).ClearContents
End Sub
 
Upvote 0
Thanks to both of you,
both great ideas and worked first time, so i've gone from no solution to two :)
thank you very much
Tony
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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