ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sum macro for a variable "i" in a loop (https://www.excelbanter.com/excel-programming/400266-sum-macro-variable-i-loop.html)

[email protected]

Sum macro for a variable "i" in a loop
 
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


Dave Peterson

Sum macro for a variable "i" in a loop
 
Sub test()
Dim i As Long
For i = 1 To 100
Range("A1").Value = application.Sum(Range("b2:B" & i))
Next i
End Sub

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


--

Dave Peterson

JE McGimpsey

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


Bob Phillips

Sum macro for a variable "i" in a loop
 
Range("A1").Value = Application.Sum(Range("B2:B & i))

is all you need, no loop

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
oups.com...
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




Dave Peterson

Sum macro for a variable "i" in a loop
 
After reading Bob's post, I'm not sure what you wanted.

Range("A1").Value = application.Sum(Range("B2:B100"))

or maybe something like:

Sub test()
Dim i As Long
For i = 1 To 100
Range("A" & i).Value = application.Sum(Range("b2:B" & i))
Next i
End Sub

Dave Peterson wrote:

Sub test()
Dim i As Long
For i = 1 To 100
Range("A1").Value = application.Sum(Range("b2:B" & i))
Next i
End Sub

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


--

Dave Peterson


--

Dave Peterson

JE McGimpsey

Sum macro for a variable "i" in a loop
 
But which "i" should be used? <g

My impression was that this was just a test...

In article ,
"Bob Phillips" wrote:

Range("A1").Value = Application.Sum(Range("B2:B & i))

is all you need, no loop


Bob Phillips

Sum macro for a variable "i" in a loop
 
I'll leave that to the OP's discretion <g^2

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"JE McGimpsey" wrote in message
...
But which "i" should be used? <g

My impression was that this was just a test...

In article ,
"Bob Phillips" wrote:

Range("A1").Value = Application.Sum(Range("B2:B & i))

is all you need, no loop




[email protected]

Sum macro for a variable "i" in a loop
 
On Oct 30, 8:57 am, JE McGimpsey wrote:
But which "i" should be used? <g

My impression was that this was just a test...

In article ,
"Bob Phillips" wrote:



Range("A1").Value = Application.Sum(Range("B2:B & i))


is all you need, no loop- Hide quoted text -


- Show quoted text -


Thanks guys.



All times are GMT +1. The time now is 01:31 PM.

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