Inserting blank line at the end of a named range copying the format a formulas from the prior line

Marro

New Member
Joined
Mar 6, 2017
Messages
8
I'm new to VBA and am looking for some additional assistance. I saw a previous post similar to my question but it's not working. Here's where I'm at:
- A7:N12 is a named range "trailer_req_lanes" A7:n8 are titles
- A13:N17 is a named range "trail_prod_queue" A13:N14 are titles
- A18:N21 is a named range "trailer_vendor_copack" A18:n19 are titles
- A22:n25 is a named range "trailer_storage" A22:n23 are titles

I want the file user to be able to add a blank line as needed to each named range. This means that the last line item in the range may or may not already have data in it. The blank line that is added should have the same format and formulas as the previous line and the range name should be adjusted for the new line.

I've tried the code several ways, attempting to use copy and pastespecial paste:=xlPasteFormulas but it's just not working. Here's what I have. Line 12 has data and when I run the code below it's copy and pasting all the date from row 12 to row 13. The named range update is working fine.

Code:
Sub addnewrow_tractor_req_lanes()
    Dim nameofrange As String
    nameofrange = "tractor_req_lanes"
    
    With Range(nameofrange)
        With .Rows(.Rows.Count) 'goes to the last row in the range named
            .copy
           .Insert shift:=xlDown 'inserts a new row below the last row in the range named
           .PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
           Application.CutCopyMode = False
           Range(.Offset(-1, 0), Range(nameofrange)).name = nameofrange
         End With
     End With
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Unforutanley I don't have admin rights to upload software to my computer so I can't attach anything. Is there another way I can show you what your looking to see?
 
Upvote 0
I figured it out by making the data into a table. Thank you for your offer of assistance.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,752
Members
448,989
Latest member
mariah3

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