0

the script below is for inserting a certain number of blank rows above or below base on the value in a certain cell. For example if the value in cell G3 is 3 then it would insert 3 rows. Tee problem I am running into is that only want to add blank rows to a selected column, in this case column E:G, because the data to he left of the worksheet in column "A:C" can't be shift down. is there anyway to update this?

Sub Insert_Rows()

Column_Number = Int(InputBox("Number of the Column on Which the Cell Values Depend: "))

Above_or_Below = Int(InputBox("Enter 0 to Insert Rows Above Each Row." + vbNewLine + "OR" + vbNewLine + "Enter 1 to Insert Rows Below Each Row."))

Dim Count As Integer
Count = 0

For i = 1 To Selection.Rows.Count
    For j = 1 To Int(Selection.Cells(i + Count, Column_Number))
        Selection.Cells(i + Above_or_Below + Count, Column_Number).EntireRow.Insert
        Count = Count + 1
    Next j
Next i

End Sub

This is the result when I use this code:

enter image description here

This is what I want it to do :

Thank you in advance!

cybernetic.nomad
  • 5,547
  • 3
  • 16
  • 26
  • 1
    Don't insert the `EntireRow`, insert a range instead. Ex.: `Range("A1").Insert Shift:=xlDown` Side note: it is usually a good idea to [avoid using Select in your code](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) – cybernetic.nomad Mar 31 '22 at 19:47

0 Answers0