Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default The long way round seems faster...

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default The long way round seems faster...

If you go to the store to get milk, eggs, and bread and get it all in one trip,
it's much quicker than making 3 separate trips.

Writing to all 4000 of those cells (B2:U201) in one step is much quicker than
writing to 4000 cells one at a time.



Sam Wilson wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default The long way round seems faster...


That's what I expected, but it takes 3 times as long.

"Dave Peterson" wrote:

If you go to the store to get milk, eggs, and bread and get it all in one trip,
it's much quicker than making 3 separate trips.

Writing to all 4000 of those cells (B2:U201) in one step is much quicker than
writing to 4000 cells one at a time.



Sam Wilson wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default The long way round seems faster...

I missed the part that said that using all cells was slower. I'd agree that
it's that UDF that must be causing the delay.

Sam Wilson wrote:

That's what I expected, but it takes 3 times as long.

"Dave Peterson" wrote:

If you go to the store to get milk, eggs, and bread and get it all in one trip,
it's much quicker than making 3 separate trips.

Writing to all 4000 of those cells (B2:U201) in one step is much quicker than
writing to 4000 cells one at a time.



Sam Wilson wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default The long way round seems faster...

Sam, the first one would be faster..

If this post helps click Yes
---------------
Jacob Skaria


"Sam Wilson" wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default The long way round seems faster...

It should be: it isn't.

The way I expected to be faster takes three times as long.

"Jacob Skaria" wrote:

Sam, the first one would be faster..

If this post helps click Yes
---------------
Jacob Skaria


"Sam Wilson" wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default The long way round seems faster...

I just stuck a "Debug.Print Time" statement at the beginning and end of each
macro and ran them on separate newly inserted worksheets... the first one
shows no difference (both statements appear to print out at the same time)
whereas your second one shows a time difference of one second. These results
were consistent over three separate trials. So, I would conclude that the
timing is in line with expectations... and the opposite of what you are
reporting. If it helps any, I am running XL2003 (SP3) on Vista (SP1).

--
Rick (MVP - Excel)


"Sam Wilson" wrote in message
...
It should be: it isn't.

The way I expected to be faster takes three times as long.

"Jacob Skaria" wrote:

Sam, the first one would be faster..

If this post helps click Yes
---------------
Jacob Skaria


"Sam Wilson" wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default The long way round seems faster...

I've stripped it down to two sub which run sequentially, logged start time
and end time for each and run a couple of hundred times. The way that should
be faster is consistently 3 time slower than the long winded way.

In the actual code (not the sample code I posted) the formula applied is a
UDF from a third party - their VB is password protected so I can't see what
it's doing but that UDF must be the cause.

It's a strange one.

"Rick Rothstein" wrote:

I just stuck a "Debug.Print Time" statement at the beginning and end of each
macro and ran them on separate newly inserted worksheets... the first one
shows no difference (both statements appear to print out at the same time)
whereas your second one shows a time difference of one second. These results
were consistent over three separate trials. So, I would conclude that the
timing is in line with expectations... and the opposite of what you are
reporting. If it helps any, I am running XL2003 (SP3) on Vista (SP1).

--
Rick (MVP - Excel)


"Sam Wilson" wrote in message
...
It should be: it isn't.

The way I expected to be faster takes three times as long.

"Jacob Skaria" wrote:

Sam, the first one would be faster..

If this post helps click Yes
---------------
Jacob Skaria


"Sam Wilson" wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default The long way round seems faster...

For me, the first method was 4-20 times faster than the second, depending on
how many times I ran it (I added an outer loop to each demo routine).

Do you experience the same slowdown with these demo routines as with your
"real" routines?

Eric

"Sam Wilson" wrote:

Hi all,

Any ideas why this:

sub demo()

application.calculation = xlcalculationmanual
range("B2:U201").formula = "=$A2&B$1"

end sub

would be so much slower than this:

sub demo()

application.calculation = xlcalculationmanual

dim i as integer
dim j as integer

for i = 1 to 200
for j = 1 to 20
range("A1").offset(i,j).formula = "=" &
range("a1").offset(i,0).address(false,true) & "&" &
range("a1").offset(0,j).address(true,false)
next j
next i

end sub

The actual formula in my code is more complex than =$A1&B$2, but the
principle is the same.

Sam

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
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Long Long Long Nested If Function sed Excel Discussion (Misc queries) 4 December 9th 09 06:44 PM
Tcl's Tcom meets Office 2003 - giving pre-.NET Visual Basic for Applications a small taste of introspection the long way round... [email protected] Excel Programming 2 February 20th 07 01:09 PM
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM
How do I ROUND() round off decimals of a column dataset? Højrup Excel Worksheet Functions 2 January 12th 05 10:50 AM


All times are GMT +1. The time now is 08:25 PM.

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"