Insert Multi Rows Between Existing Data

Solved/Closed
froggy6703 - Mar 6, 2010 at 11:18 AM
 SWAJI - Nov 19, 2014 at 07:02 AM
Hello,

I am trying to create a macro that will insert a set amount of blank rows into a existing spreadsheet after each entry. The amount of rows needed will be the same for each entry on the spreadsheet, but will need to be changed each time it is used.

Here is a sample...
Currently:
Title1
Title2
Title3
Title4

After Macro:
Title1


Title2


Title3


Title4

The amount of blank row can be anywhere from 20 - 40. I am hoping I can use some sort of Input box to get the number of rows needed so I don't need to modify to code each time.

Thank you and let me know if you can help.

Matt
Related:

5 replies

venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
805
Mar 6, 2010 at 09:47 PM
A1 is having headings.
then try this macro
KEEP YOUR ORIGINAL FILE SAFELY SOMEWHERE
FIRST DO THE TESTING OF MACRO IN THE EXPERIMENTAL DATA YOU HAVE SENT
Sub test()
Dim j As Long, r As Range
j = InputBox("type the number of rows to be insered")
Set r = Range("A2")
Do
Range(r.Offset(1, 0), r.Offset(j, 0)).EntireRow.Insert
Set r = Cells(r.Row + j + 1, 1)
MsgBox r.Address
If r.Offset(1, 0) = "" Then Exit Do
Loop

End Sub
14
This works great, thank you for your quick response. The only thing I don't like is the pop-up box that tells you where the cell was entered. This is good to have but the spreadsheets I am working with can have up to 500-1000 lines. Meaning I have to hit Enter 500-1000 times to get through them all. Is it possible to remove that pop-up box?

Thanks again,

Matt
0
yes, just delete the line "MsgBox r.Address"
0
thank you
0
This is really nice one (yes, just delete the line "MsgBox r.Address") this is correct.
0
Great! Thanks for sharing the macro.
0
venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
805
Mar 7, 2010 at 07:30 PM
sorry that is not the imput box but a message box. I have made that non operational copy this now

I have put an apostrophe in the beginning of the line "msgbox ......." to make it unoperable


Sub test()
Dim j As Long, r As Range
j = InputBox("type the number of rows to be insered")

Set r = Range("A2")
Do
Range(r.Offset(1, 0), r.Offset(j, 0)).EntireRow.Insert
Set r = Cells(r.Row + j + 1, 1)
'MsgBox r.Address(the apostrophe in the beginning of this line makes this line non operable)
If r.Offset(1, 0) = "" Then Exit Do
Loop

End Sub
6
This works great, thank you for helping with this.

Matt
0
Fairooz Mehedad
May 22, 2010 at 03:47 AM
Thanks man...was looking for something like this
0
just saved me loads of time.

Now just need something to copy the row immediately above the spaces into the now empty rows...
0
I've got no macro ability at all, but just dropped this into my excel 2003 and followed your instructions - it worked!
Thanks heaps
0
This works great. Thank you.
0
venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
805
Feb 4, 2011 at 04:25 AM
QUOTE
gah123 - Feb 4, 2011 8:00am GMT
just saved me loads of time.

Now just need something to copy the row immediately above the spaces into the now empty rows...
UNQUOTE

my previous message 10 month old. will it be possible for you to open a new thread
3
venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
805
Mar 7, 2010 at 09:43 AM
I did not understand. pop up box comes only once .once you enter for e.g then there will be 3 blank rows between the entries. you yourself said "I can use some sort of Input box " . please clarify your doubt with some examples.
0
Sorry if that didn't make sense, but I get the Input box, and that part works great. But then after each insert there is another pop-up that just has a cell name with an OK button. This then has to be pressed after each insert. I am wondering if there is a way to remove this pop-up box, but still keeping the input box.

Thank you,

Matt
0

Didn't find the answer you are looking for?

Ask a question
bhunesh7
Posts
1
Registration date
Thursday January 31, 2013
Status
Member
Last seen
January 31, 2013

Jan 31, 2013 at 05:28 AM
9827755762
0