×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Excel 2016 Macro/VBA insert rows

Excel 2016 Macro/VBA insert rows

Excel 2016 Macro/VBA insert rows

(OP)
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.

RE: Excel 2016 Macro/VBA insert rows

Hi,

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

Please post your code.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel 2016 Macro/VBA insert rows

(OP)
I want this to loop possibly hundreds of times. I want it to stop automatically when it reaches a blank cell

RE: Excel 2016 Macro/VBA insert rows

Quote:

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

Please post your code.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel 2016 Macro/VBA insert rows

Got that macro recorded yet for one sequence?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel 2016 Macro/VBA insert rows

(OP)
One sequence

Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
ActiveCell.Offset(5, 0).Range("A1").Select

RE: Excel 2016 Macro/VBA insert rows

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel 2016 Macro/VBA insert rows

(OP)
Works great. Thank you very much or your time.bigsmile

RE: Excel 2016 Macro/VBA insert rows

MM1963, don't you think Skip deserves a star for such great and quick help he provided?
Click on Great Post! link on his reply to award him a star.


---- Andy

There is a great need for a sarcasm font.

RE: Excel 2016 Macro/VBA insert rows

(OP)
Sure will. Didn't know to do that.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close