ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   VBA code for Sum and diff (https://www.excelbanter.com/excel-worksheet-functions/448470-vba-code-sum-diff.html)

dhir

VBA code for Sum and diff
 
I want VBA Code for formula which is like this

The Formula is in loop
i value keep on changing in loop
Di=Ai+B(i-1)-C(i-2)

So in D10 then formula should be like this =A10+B9-C8

I don't want R1C1 Method


I am trying for last two weeks...

Regards
Dhir






Claus Busch

VBA code for Sum and diff
 
Hi,

Am Sun, 24 Mar 2013 21:31:42 -0700 (PDT) schrieb dhir:

I want VBA Code for formula which is like this

The Formula is in loop
i value keep on changing in loop
Di=Ai+B(i-1)-C(i-2)

So in D10 then formula should be like this =A10+B9-C8


you don't have to loop. You can autofill the formula.
Try:

Sub Test()
Dim LRow As Long
LRow = Cells(Rows.Count, 1).End(xlUp).Row

Range("D3").Formula = "=A3+B2-C1"
Range("D3").AutoFill Range("D3:D" & LRow)
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


All times are GMT +1. The time now is 02:58 AM.

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