开发者

how to write macro for summing for dynamic rows

I am using excel 2010 and retrieving data from SQL analysis service.

When I refresh the data from excel , rows become d开发者_开发百科ynamics as it is bind to external datasource. I am adding a seperate columns with formula for summing total amount.

With increment or decrement of rows in excel , alignment of custom columns goes out.

How can I resolve this problem that summing of values become dynamic with adding and removal of rows ?

How to write a macro for doing this task ?

This what i am trying , but i am getting the following error :

Public Sub ProcessData()
Dim i As Long
 Dim iLastRow As Long
Dim iStart As Long

With Sheet1

   iLastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
 iStart = 5
  For i = 1 To iLastRow + 1
  If .Cells(i, "C").Value <> "" And .Cells(i, "B").Value <> "" Then
.Cells(i, "D").Value = 
 Application.Sum(.Range(.Cells(iStart, "C").Value + .Cells  (   iStart, "B").Value))
iStart = i + 1
End If
Next i
 End With
 End Sub

how to write macro for summing for dynamic rows


When you create a connection to a database (or other data source) formulas place in columns next to the imported data are adjusted on refresh to cope with this excat issue. These formulas will typically be in the form =SomeFunction([@ColumnName], ...)

Likewise Sums of the form =SUM(ConnectionName[ColumnName]) will automatically be right when the connection is refreshed

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜