How to fill formula down till last row in column

adelvoira

New Member
Joined
Sep 9, 2017
Messages
35
How to get my VBA code to draw down the formula that's in cell F121 all the way down to the end of the data set. So in excel my formula is =F120+D121-E121
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about
Code:
Sub copyDown()
   Range("F121", Range("E" & Rows.Count).End(xlUp).Offset(, 1)).FillDown
End Sub
 
Upvote 0
It's not working
here is my vba code:
Code:
Sheets("CARBURANTS").ActivateFor i = 1 To Sheets("CARBURANTS").Range("b" & Rows.Count).End(xlUp).Row
If Sheets("CARBURANTS").Cells(i, 2).Value = Me.TextBox105 Then
If ListBox2.List(i, 1) = "gasoil" Then
Sheets("CARBURANTS").Cells(i, 6).Value = Sheets("CARBURANTS").Cells(i - 1, 6).Value + Sheets("CARBURANTS").Cells(i, 4).Value - Sheets("CARBURANTS").Cells(i, 5).Value
End If
i = i - 1
End If
Next i
 
Upvote 0
You haven't got a formula, you have a constant and your code isn't starting in F121, it is going from F1 to whatever the last data is in column B.

What do you get with the below assuming that you are actually starting in F2 and the code below doesn't use column B, it uses whatever is the longest column (if you actually want F121 change the F2 in the code)...


Code:
    With Sheets("CARBURANTS").
        With .Range("F2", .Range("F" & .Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row))
            .FormulaR1C1 = "=R[-1]C+RC[-2]-RC[-1]"
            .Value = .Value
        End With
    End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,914
Members
449,132
Latest member
Rosie14

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