Extend a formula to next row only if the next row contains data

mc2312

New Member
Joined
Apr 19, 2019
Messages
8
Looking for a way to extend a formula to the next row but only if the next row contains data

e.g. if C1 contains =IF(A1="","",A1+10)

is there a way to automatically extend the formula to C2 if (and only if) data is entered into A2? And then on to C3, C4 etc.

The idea is to set up a template with only the formula in Row 1, and for the formula to copy down only as far as it is needed - to avoid having to copy the formula down to row 20,000!

I know excel will do this automatically if there are 4 similar rows, but in this situation only the top row can contain the formula.

Thanks!
 
A formula can not create another formula or a formula can not create itself, so to speak.
One way to create the formulas is with VBA code.


With the following code, each time you select sheet2, the formulas are created according to the cells used in column A of sheet1

Code:
Private Sub Worksheet_Activate()
    With Range("B2:B" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row)
        .FormulaR1C1 = "=sheet1!RC[-1]"
    End With
End Sub



Right click the tab of the sheet you want this to work (sheet2), select view code & paste the code into the window that opens up.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Thanks James. It creates a circular reference.. I now realise the question is simply 'how to copy a formula to a variable number of rows' (the variable number being the count of rows on the other sheet). I have found that you can do this using a macro so it's maybe a good reason to learn a bit about VBA. Thanks again for your help..
 
Upvote 0
I'm glad to help you. Let me know if you have any doubt.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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