vba entering a formula in a certain cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I need some help with vba programming by creating a formula in cell g6

The Formula i like to enter in this cell = f6 - e6, but then each month the
number of rows will change. I need to be able to copy this formula down
based on the number of rows under row 6.

Can you help me?
Thanks
 
see if this is what you need:

Sub insert_formulas()
Dim ws As Worksheet
Dim lastorw As Long
Set ws = Worksheets("Sheet1")
Dim lastrow As Long
lastrow = ws.Cells(Rows.Count, "E").End(xlUp).Row

With ws.Range("G6:G" & lastrow)
.Formula = "=F6-E6"
End With
End Sub
 
Hi Gary,

Worked great thanks


Gary Keramidas said:
see if this is what you need:

Sub insert_formulas()
Dim ws As Worksheet
Dim lastorw As Long
Set ws = Worksheets("Sheet1")
Dim lastrow As Long
lastrow = ws.Cells(Rows.Count, "E").End(xlUp).Row

With ws.Range("G6:G" & lastrow)
.Formula = "=F6-E6"
End With
End Sub
 
Back
Top