Macro to find end of column data

  • Thread starter Thread starter briandhowells
  • Start date Start date
B

briandhowells

I have a range of data (ex: A1:F20) and in the column (g) next to the
data i have a formula that adds certain fields. I am constantly
adding rows of data, so what I want is a macro that will find the last
row of data in column F, then paste the formula from the last row of
column G down to that row. Any help is appreciated. Thanks in
advance.
 
One way...

Sub CopyFormula()
Dim rngToCopy As Range
Dim rngLast As Range

Set rngToCopy = Cells(Rows.Count, "G").End(xlUp)
Set rngLast = Cells(Rows.Count, "F").End(xlUp)

If rngToCopy.Row < rngLast.Row Then _
rngToCopy.Copy Range(rngToCopy.Offset(1, 0), rngLast.Offset(0, 1))

End Sub
 
Perfect. Thanks!

One way...

Sub CopyFormula()
Dim rngToCopy As Range
Dim rngLast As Range

Set rngToCopy = Cells(Rows.Count, "G").End(xlUp)
Set rngLast = Cells(Rows.Count, "F").End(xlUp)

If rngToCopy.Row < rngLast.Row Then _
rngToCopy.Copy Range(rngToCopy.Offset(1, 0), rngLast.Offset(0, 1))

End Sub
--
HTH...

Jim Thomlinson





- Show quoted text -
 

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

Back
Top