user2788764
user2788764

Reputation: 11

Macro is inserting blank line above text not after

The following macro that I adapted from an existing one is supposed to insert a blank line with the words TOTAL CALLS: after the word Summary:.

The problem is that it is adding that blank line above the Summary: line not below it.

This is probably a simple fix but I just don't see where the error is as I don't know enough VB to not mess it up completely. This macro will help me avoid having to manually add about 400 blank rows once a week. Thank you in advance for any help!

Sub Insert() 
    Dim rng As Range 

    Set rng = Range("D1") 
    While rng.Value <> "" 
        If rng.Value = "Summary" Then 
            rng.EntireRow.Insert 
            rng.Offset(1, 0) = "TOTAL CALLS" 
            Set rng = rng.Offset(1) 
        End If 
        Set rng = rng.Offset(1) 
    Wend 
End Sub 

Upvotes: 1

Views: 1138

Answers (1)

David Zemens
David Zemens

Reputation: 53623

The Insert method always inserts like this.

If you need to insert a row after a range, you need to use Offset or some other method to specify where the inserted row belongs.

rng.Offset(1,0).EntireRow.Insert

Upvotes: 1

Related Questions