VBA to ClearContents but keep Formulas!?

thelostscott

Board Regular
Joined
May 7, 2010
Messages
226
Can someone please give me some advice on adding a row whilst keeping formulas in place?

Currently I have the below code:
Code:
Sub Add_Row()
Application.ScreenUpdating = False
 
With Range("D14").End(xlDown)
    With .EntireRow
        .Insert
        .Offset(-1, 0).FormulaR1C1 = .FormulaR1C1
        .ClearContents
    End With
End With

Application.ScreenUpdating = True
End Sub
I need to keep the formulas in place in variable rows and not have them deleted.

Any Ideas?
 
Ah, that one would probably be thrown off because I have a summary table below this table that it will be trying to reference with the (xlUp) code. Apologies on that one.

I'm still unsure why this wouldn't work?

Code:
If Range("D14").End(xlDown).Offset(-1) <> "" Then
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
So should it be?

Code:
Sub Add_Row()
Application.ScreenUpdating = False
If Range("D14").End(xlDown).Value <> "" Then
    With Range("D14").End(xlDown)
        With .EntireRow
            .Copy
            .Insert
            On Error Resume Next
            .SpecialCells(xlCellTypeConstants).ClearContents
            On Error GoTo 0
        End With
    End With
End If
Application.ScreenUpdating = True
End Sub

Otherwise I don't think I understand what you are trying to do.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,894
Members
452,948
Latest member
Dupuhini

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