Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default most efficient large range summing?

This simple routine has crept into my code and I use it thoughtlessly and
often:

For i = 1 To 50000 ' some seriously large value here!
Range("C" & i).Value = Range("A" & i).Value + Range("B" & i).Value
Next i

I discovered it is a time-consumer, searched for alternatives and found
several, but am just not VBA fluent enough to judge their efficiency.

Any more experienced programmers can help me find the truly fastest solution?

Thanks!

-Joni
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default most efficient large range summing?

One way:

With Range("C1:C50000")
.Formula = "=A1+B1"
.Value = .Value
End With

In article ,
jonigr wrote:

This simple routine has crept into my code and I use it thoughtlessly and
often:

For i = 1 To 50000 ' some seriously large value here!
Range("C" & i).Value = Range("A" & i).Value + Range("B" & i).Value
Next i

I discovered it is a time-consumer, searched for alternatives and found
several, but am just not VBA fluent enough to judge their efficiency.

Any more experienced programmers can help me find the truly fastest solution?

Thanks!

-Joni

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default most efficient large range summing?

Another:

Const RowCount As Long = 50000

Sub Alt2()
Dim Arr1 As Variant
Dim Arr2 As Variant
Dim Counter As Long
Arr1 = Range("A1").Resize(RowCount).Value
Arr2 = Range("B1").Resize(RowCount).Value
For Counter = 1 To RowCount
Arr1(Counter, 1) = Arr1(Counter, 1) + Arr2(Counter, 1)
Next
Range("C1").Resize(RowCount).Value = Arr1
End Sub


--
Jim
"jonigr" wrote in message
...
| This simple routine has crept into my code and I use it thoughtlessly and
| often:
|
| For i = 1 To 50000 ' some seriously large value here!
| Range("C" & i).Value = Range("A" & i).Value + Range("B" & i).Value
| Next i
|
| I discovered it is a time-consumer, searched for alternatives and found
| several, but am just not VBA fluent enough to judge their efficiency.
|
| Any more experienced programmers can help me find the truly fastest
solution?
|
| Thanks!
|
| -Joni


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default most efficient large range summing?

I am delighted!

Jim's slightly more complex code (I'm still deciphering it) is actually the
winner with an exec. time of... 0.11 sec.

JE is close 2nd with 0.14 sec.

But compared to my monstrous... 5.5 sec... both are winners: over 40x faster!

I expected improvement, but not that much, so I wonder: is there a good
resource dedicated to VBA *efficiency*: speeding up existing routines etc.?

Thanks very much!

-Joni

"Jim Rech" wrote:

Another:

Const RowCount As Long = 50000

Sub Alt2()
Dim Arr1 As Variant
Dim Arr2 As Variant
Dim Counter As Long
Arr1 = Range("A1").Resize(RowCount).Value
Arr2 = Range("B1").Resize(RowCount).Value
For Counter = 1 To RowCount
Arr1(Counter, 1) = Arr1(Counter, 1) + Arr2(Counter, 1)
Next
Range("C1").Resize(RowCount).Value = Arr1
End Sub


--
Jim
"jonigr" wrote in message
...
| This simple routine has crept into my code and I use it thoughtlessly and
| often:
|
| For i = 1 To 50000 ' some seriously large value here!
| Range("C" & i).Value = Range("A" & i).Value + Range("B" & i).Value
| Next i
|
| I discovered it is a time-consumer, searched for alternatives and found
| several, but am just not VBA fluent enough to judge their efficiency.
|
| Any more experienced programmers can help me find the truly fastest
solution?
|
| Thanks!
|
| -Joni



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default most efficient large range summing?

i like to use what I call a poor-man's version of list processing...

[C1:C50000] = [A1:A50000+B1:B50000]

HTH
Dana DeLouis

jonigr wrote:
This simple routine has crept into my code and I use it thoughtlessly and
often:

For i = 1 To 50000 ' some seriously large value here!
Range("C" & i).Value = Range("A" & i).Value + Range("B" & i).Value
Next i

I discovered it is a time-consumer, searched for alternatives and found
several, but am just not VBA fluent enough to judge their efficiency.

Any more experienced programmers can help me find the truly fastest solution?

Thanks!

-Joni



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default most efficient large range summing?

Woooh, an absolute winner with 0.06 sec!

I had to look up the use of the square brackets, never seen that before.

Was curious to see if a Range version of this works as well, like:

Range("C1", "C50000") = Range("A1", "A50000") + Range("B1", "B50000")

but obviously that doesn't.

My VBA manual (or VB Help) doesn't seem to mention this list processing
method at all. Any documentation you can point me to?

Thanks!

-Joni

"Dana DeLouis" wrote:

i like to use what I call a poor-man's version of list processing...

[C1:C50000] = [A1:A50000+B1:B50000]

HTH
Dana DeLouis

jonigr wrote:
This simple routine has crept into my code and I use it thoughtlessly and
often:

For i = 1 To 50000 ' some seriously large value here!
Range("C" & i).Value = Range("A" & i).Value + Range("B" & i).Value
Next i

I discovered it is a time-consumer, searched for alternatives and found
several, but am just not VBA fluent enough to judge their efficiency.

Any more experienced programmers can help me find the truly fastest solution?

Thanks!

-Joni


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
Large Time totals not summing. Brik Excel Worksheet Functions 3 November 5th 07 07:20 PM
Large Time values not summing Sam Excel Worksheet Functions 2 November 5th 07 06:19 PM
more efficient way to lookup a range? [email protected] Excel Discussion (Misc queries) 1 May 12th 06 05:41 AM
Summing large numbers... Buildscharacter Excel Worksheet Functions 3 November 13th 05 08:02 PM
Summing large columns Muttley Excel Worksheet Functions 1 October 27th 05 02:20 PM


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

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

About Us

"It's about Microsoft Excel"