Forum

Insert rows with fo...
 
Notifications
Clear all

Insert rows with formatting based on a cell value - automatically

2 Posts
2 Users
0 Reactions
72 Views
(@ellonash)
Posts: 1
New Member
Topic starter
 

Good Day, 

I need to create a sheet, that when a cell is a completed with a specific number, that number of rows (specified in the cell) would automatically be inserted (without me having to run the macro. And when it inserts rows, the formatting of the line above should be duplicated / copied. Please see the macro below and advise if you can modify and assist me please? 

The current macro is only inserting the rows, no formatting or automation in inserting the rows - Please see below - I've attached the Excel Workbook as well

Sub Insert()
'UpdatebyExtendoffice20170926
Dim xRg As Range
Dim xAddress As String
Dim I, xNum, xLastRow, xFstRow, xCol, xCount As Long
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Select a range to use(A1:H1):", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
xLastRow = xRg(1).End(xlDown).Row
xFstRow = xRg.Row
xCol = xRg.Column
xCount = xRg.Count
Set xRg = xRg(1)
For I = xLastRow To xFstRow Step -1
xNum = Cells(I, xCol)
If IsNumeric(xNum) And xNum > 0 Then
Rows(I + 1).Resize(xNum).Insert 
xCount = xCount + xNum
End If
Next
xRg.Resize(xCount, 1).Select
Application.ScreenUpdating = True
End Sub

Your help would be much appreciated

Thank you

 
Posted : 08/11/2018 10:15 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Natasha,

there's no attached workbook.

Regards

Phil

 
Posted : 08/11/2018 6:27 pm
Share: