Offset Rows Loop by Value in AH

manthony

New Member
Joined
Dec 5, 2016
Messages
40
Hi, I am struggling with my code below and I am hoping someone can help.

I have a formula in column AP that returns a number or a blank. I am trying to write some code so that if my formula in column AP returns a number then offset/insert (X) number of rows below based on the value in column AH. For example if cell AP2 = 1 and the value in AH2 is 3 then 3 rows will be inserted below AP2. The values in AH vary. Below is what I have so far.


Sub Macro4()
'
' Macro4 Macro


Last = Cells(Rows.Count, "AP").End(xlUp).Row
For i = Last To 1 Step -1
If IsNumeric(Cells(i, "AP").Value) Then
Cells(i, "AP").Offset(RowOffset:=(Cells(i, "AH").Value)).EntireRow.Insert
End If
Next i

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

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
635
Office Version
  1. 365
Platform
  1. Windows
Hi. Try:
Code:
Sub Macro4V2()
 Dim Last As Long, i As Long
 Last = Cells(Rows.Count, "AP").End(xlUp).Row
  For i = Last To 1 Step -1
   If IsNumeric(Cells(i, "AP").Value) Then
    Rows(i + 1 & ":" & i + Cells(i, "AH")).EntireRow.Insert
   End If
  Next i
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,383
Messages
5,635,942
Members
416,889
Latest member
dhegs

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
Top