ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copy formula using vba based on row count (https://www.excelbanter.com/excel-programming/326300-copy-formula-using-vba-based-row-count.html)

Jeff

copy formula using vba based on row count
 
Hi all,
I have a spreadsheet that number of elements in Col A to Col D will
change (they have some # of items). e.g.
Row 1 is the header
Row 2 contain the descriptions.
Row 3 to whatever are the values.

Cell(E3).value = formula based on value in A3.. D3
Cell(E4).value = formula based on value in A4.. D4

How do I use VBA to copy the formula to the Col E based on number of items
in ColA?


Thanks.

Bob Phillips[_6_]

copy formula using vba based on row count
 

iLastRow = Cells(Rows.Count,"A").End(xlUp).Row
For i = 3 To iLastRow
Cells(i,"E").Formula = "=SUM(A" & i & ":D" & i & ")"
Next i

The formula will change to your formula.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jeff" wrote in message
...
Hi all,
I have a spreadsheet that number of elements in Col A to Col D will
change (they have some # of items). e.g.
Row 1 is the header
Row 2 contain the descriptions.
Row 3 to whatever are the values.

Cell(E3).value = formula based on value in A3.. D3
Cell(E4).value = formula based on value in A4.. D4

How do I use VBA to copy the formula to the Col E based on number of items
in ColA?


Thanks.





All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com