insert rows at change in values

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
528
Office Version
  1. 365
Platform
  1. Windows
Hi all

i have this below macro that inserts a line when there is a change in a certain column

i would like for another input box to ask me how many lines i want to add and based on what i enter in that input box it will create the number of blank lines that i need
i don't always want to change this code "Rows(lRow).EntireRow.Insert"


Sub InsertRowAtChangeInValue()
Dim BB As String
Dim lRow As Long
BB = Application.InputBox(Prompt:="Enter the cell address")
For lRow = Cells(Cells.Rows.Count, BB).End(xlUp).Row To 2 Step -1
If Cells(lRow, BB) <> Cells(lRow - 1, BB) Then
Rows(lRow).EntireRow.Insert
Rows(lRow).EntireRow.Insert
End If
Next lRow
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this:

Code:
Sub InsertRowAtChangeInValue()
Dim BB As String
Dim lRow As Long
Dim ans As Long
 
    BB = Application.InputBox(Prompt:="Enter the cell address")
    ans = Application.InputBox(Prompt:="How Many Rows to Insert")
 
        For lRow = Cells(Cells.Rows.Count, BB).End(xlUp).Row To 2 Step -1
            If Cells(lRow, BB) <> Cells(lRow - 1, BB) Then
                Rows(lRow).Resize(ans).Insert
            End If
        Next lRow
 End Sub
 
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,257
Members
448,880
Latest member
aveternik

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
Back
Top