Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2016 Macro/VBA insert rows

Status
Not open for further replies.

MM1963

Vendor
Feb 15, 2018
38
US
Looking for help with some code.
After I select a cell I want to execute a macro that will do the following.
Insert 4 blanks rows, then move down 5 rows. If the new cell is blank, stop the macro, if not insert 4 blank rows, then move down 5 rows. Loop.
Any help would be appreciated.
 
Hi,

Did you try turning on your macro recorder and recording a sequence?

Please post your code.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I want this to loop possibly hundreds of times. I want it to stop automatically when it reaches a blank cell
 
Did you try turning on your macro recorder and recording a sequence?

Please post your code.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Got that macro recorded yet for one sequence?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
One sequence

Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
ActiveCell.Offset(5, 0).Range("A1").Select
 
This solution is more general, in that you can vary the number of rows...

Code:
Sub test()
    InsrtRoz 4
End Sub

Sub InsrtRoz(iNumRows As Integer)
    If Selection.Count = 1 Then
        Do
            With Range(Selection.EntireRow, Selection.Offset(iNumRows - 1).EntireRow)
                .Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            End With
            Selection.Offset(iNumRows + 1).Select
        Loop Until Selection = ""
    Else
        MsgBox "Plz SELECT a single cell"
    End If
End Sub

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Works great. Thank you very much or your time.[bigsmile]
 
MM1963, don't you think Skip deserves a star for such great and quick help he provided?
Click on [blue]Great Post![/blue] link on his reply to award him a star.


---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top