vba entering a formula in a certain cell

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
 
G

Gary Keramidas

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top