rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 569
- Office Version
- 365
- Platform
- Windows
I have the code listed below which will insert a blank row until the second row of my selected range. I want to be able to use a template row of formulas to be inserted in each instance. I need to know what the correct code is for step 4 to make sure that all my formulas get added to the new rows.
Row 4 of my spreadsheet is to be my template row and I don't know if I need to define MyRow as:
1) MyRow = Rows(4).EntireRow
2) MyRow = Rows(4)
3) Set MyRow = Rows(4).EntireRow
4) Set MyRow = Rows(4)
Thanks
Row 4 of my spreadsheet is to be my template row and I don't know if I need to define MyRow as:
1) MyRow = Rows(4).EntireRow
2) MyRow = Rows(4)
3) Set MyRow = Rows(4).EntireRow
4) Set MyRow = Rows(4)
Thanks
VBA Code:
'Step1: Declare all of the needed variables.
Dim MyRow As Long
Dim MyRange As Range
Dim sht As Worksheet
Dim LastRow As Long
Dim iCounter As Long
'Step 2: Define the variables.
MyRow = Rows(4).EntireRow
Set sht = ActiveSheet
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
Set MyRange = Rows("4:" & LastRow)
'Step 3: Start reverse looping through the range.
For iCounter = MyRange.Rows.Count To 2 Step -1
'Step 4: Insert blank row.
MyRange.Rows(iCounter).EntireRow.Insert