View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Sum macro for a variable "i" in a loop

One way:

Public Sub test()
Dim i As Integer
For i = 1 To 100
Range("A1").Value = _
Application.WorksheetFunction.Sum("B2:B" & i)
Next i
End Sub

In article .com,
wrote:

I am trying to do the following sum macro but I get an error for the
sum fomula. I want to sum the values from range B2 to B&i, the
corresponding value of "i".. Please let me know how do I do this.
Thanks

Sub test()
Dim i As Integer
For i = 1 To 100
Range("A1").Value = Sum(Range(B2, B&i))
Next i
End Sub