Insert row here ... or not

B

BrianDP1977

I stumbled across this code on another site. It functions like I nee
it to (i.e. inserts a row after the last row of data along with an
equations in the row while also deleting anything that is not a
equation) except that in it's current state it defines the last ro
where the row is to be inserted by locating the last row on the shee
containing data and inserting it there. Instead, I want to be able t
restrict the code to a specific range on the sheet where it is to plac
the new row (i.e. my sheet contains various sections of data ... I wan
to define the rows that make up one of these sections (let's say A4:A
named as D_Names) and have the code insert a row at the end of thi
section instead of at the bottom of the entire sheet). Here's th
code:


Code
-------------------
Private Sub CommandButton1_Click()
Dim LastRow As Range

Set LastRow = [A65536].End(xlUp).EntireRow
With LastRow
.Offset(1, 0).Insert
.Copy .Offset(1, 0)
On Error Resume Next
.Offset(1, 0).SpecialCells(xlCellTypeConstants, 23).ClearContents
On Error GoTo 0
End With
End Su
 
R

Rowan Drummond

Maybe:

Sub test()
Dim nm As Name
Dim iRow As Long
Set nm = ThisWorkbook.Names("D_Names")
iRow = Mid(nm.RefersTo, InStrRev(nm.RefersTo, "$"), 255)
With Rows(iRow)
.Offset(1, 0).Insert
.Copy .Offset(1, 0)
On Error Resume Next
.Offset(1, 0).SpecialCells(xlCellTypeConstants, 23). _
ClearContents
On Error GoTo 0
End With

End Sub

Hope this helps
Rowan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top