How to create a macro that will pull down a formula in a data spreadsheet

Hallliz999

New Member
Joined
Jun 5, 2018
Messages
1
Hello,
I'm looking to create a macro of a complex formula that can be applied to excel and will drop down the formula in the cells where data is present.
I can do this very simply in excel but when I use the macro and additional or less data appears, the formula only work in the array of the recorded macro.

I am hoping to manually update the macro so it fills the formula depending on the data exported each time.

Below is a very basic example:
I believe I need to fix Range("C1:C114").Select
Please let me know if you can help!

Sub Macro1()
'
' Macro1 Macro
'
'
Range("C1").Select
ActiveCell.FormulaR1C1 = "=RC[-2]+RC[-1]"
Range("C1").Select
Selection.AutoFill Destination:=Range("C1:C114")
Range("C1:C114").Select
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
No need to select cells or autofill, and you can make this dynamic by searching for the last filled row in A:B.
Code:
Sub Macro1()
Dim LastRow As Long
LastRow = Range("A:B").Find(what:="*", after:=[A1], searchdirection:=xlPrevious).Row
Range("C1:C" & LastRow).FormulaR1C1 = "=RC[-2]+RC[-1]"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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