View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default 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