matthiasarnbert
New Member
- Joined
- Oct 3, 2022
- Messages
- 2
- Office Version
- 2019
- Platform
- Windows
Hi. I'm trying to create a button that will insert a new row on the second row of a named range. I would like this new row to keep the same formatting and formulas as the row below it. The below code works well in terms of adding the new row on the second row of the named range. However, what do I need to add to also keep the formulas and formatting from the row below it? Any advice is appreciated!
Private Sub CommandButton1_Click()
Dim oRange As Range
Dim iColumns As Integer
Dim iRow As Integer
'Use Object variables to make code more legible
Set oRange = Worksheets("Sheet1").Range("Meals")
'Get Columns Width of named range
iColumns = oRange.Columns.Count
'Target the second row of the named range
iRow = 2
Set oRange = Range(oRange.Cells(iRow, 1), oRange.Cells(iRow, iColumns))
oRange.Insert Shift:=xlDown
End Sub
Private Sub CommandButton1_Click()
Dim oRange As Range
Dim iColumns As Integer
Dim iRow As Integer
'Use Object variables to make code more legible
Set oRange = Worksheets("Sheet1").Range("Meals")
'Get Columns Width of named range
iColumns = oRange.Columns.Count
'Target the second row of the named range
iRow = 2
Set oRange = Range(oRange.Cells(iRow, 1), oRange.Cells(iRow, iColumns))
oRange.Insert Shift:=xlDown
End Sub