Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read ".dll" files, the Macro "work flow" and the actual values of the variables when Macro is running [email protected] Excel Programming 5 May 16th 07 08:18 PM
"Type mismatch" when I try to fill an Array variable with "+" [email protected] Excel Discussion (Misc queries) 1 April 17th 07 01:28 PM
Question on determining "ROW" inside of a "For .. RANGE " loop David Schrader[_2_] Excel Programming 2 January 3rd 07 08:18 PM
Excel macro "loop" Leon Obers Excel Programming 2 August 24th 06 09:21 AM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM


All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"