Copy Formula to empty Cell in Range and then duplicate to the end of the range

jjtechtech

New Member
Joined
Nov 4, 2019
Messages
7
I have an instance where I would like a formula restored to a range of cells in the event that it is removed by a user. I would like the formula restored beginning with the first empty cell in the range.

Sample
A7l8k7x2c3Z0AAAAAElFTkSuQmCC


Sample Formula to restore = I5
Sample Range = C2:C16
In this instance the first empty Cell in the Range would be C5
I would like the formula copied to C5:C16
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi & welcome to MrExcel.
Do you just want to put the formula in the blank cells within C2:C16?
 
Upvote 0
Yes. Sorry been searching for ways to get a sample picture added to better describe what I am trying to do.
 
Upvote 0
How about
Code:
Sub jjtech()
    On Error Resume Next
    Range("C2:C16").SpecialCells(xlBlanks).FormulaR1C1 = "=rc9"
    On Error GoTo 0
End Sub
 
Upvote 0
Wow! That was quick. Where would I tell it the location of the formula to copy? Let's say the formula to copy is in cell I5?
 
Upvote 0
I tried running the vba code and it basically copied the text that was in cell I5 but not the formula. C5's formula was then =$I5...
 
Upvote 0
Thanks for all your help. Was finally able to get the following code to work for me.
Sub FormulaRestore()
On Error Resume Next
Range("I5").Copy
Range("C2:C16").SpecialCells(xlBlanks).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
On Error GoTo 0
End Sub
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,387
Members
449,445
Latest member
JJFabEngineering

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