GoTo Cell and loop down until blank cell found, insert new row as above

LittlegmoonBH

New Member
Joined
May 2, 2019
Messages
15
Hi All,

I'm trying to add a macro to a template that' proving tricky.

Basically, the macro needs to go to cell "C4" then loop down a variable amount of times until it hits a blank cell, it then needs to add a blank row using the formatting from the above populated row without any data.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the Board!

See if this does what you want:
Code:
Sub MyMacro()

    Dim r As Long
    
'   Find first blank row below C4
    If Range("C5") = "" Then
        r = 5
    Else
        r = Range("C4").End(xlDown).Row + 1
    End If
    
'   Insert blank row
    Rows(r).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    
End Sub
 
Upvote 0
Legend! It gives me what I need, the only thing I need to figure out is how bring down the formatting from the cells above. The above adds a row, but doesn't bring down the borders :)
 
Upvote 0
Hmmm...

Mine seemed to extend it down automatically. Let try it explicitly like this:
Code:
Sub MyMacro()

    Dim r As Long
    
'   Find first blank row below C4
    If Range("C5") = "" Then
        r = 5
    Else
        r = Range("C4").End(xlDown).Row + 1
    End If
    
'   Insert blank row
    Rows(r).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    
'   Copy formatting from row above
    Rows(r - 1).Copy
    Range("A" & r).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,800
Members
449,127
Latest member
Cyko

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