Programmatically calculating formulas for new entries

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

Guest

Hi there,

I have a series of data that is imported into specific rows/columns. There
are a number of calculated columns, that for now, i have to copy and paste
down to each new row.

Question: is there a way to have the calculations done with out having to
manually pull them down to each new row?
 
Sub Fillformulas()
Dim rng As Range, lastRow As Long
Dim cell As Range
Set rng = Rows(2).SpecialCells(xlFormulas)
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
If lastRow > 2 Then
For Each cell In rng
cell.Offset(1, 0).Resize(Rows.Count - 2, 1).ClearContents
cell.Resize(lastRow - 1, 1).Formula = cell.Formula
Next
End If

End Sub

Might give you some ideas. I have made a lot of assumptions. I assume you
have data starting in A2 with headers in row 1 and your formulas are at least
in row 2. Also, that column 1 can be used to determine the extent of the
data.

If you want to just test it, do it on a copy of your data/workbook.
 

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