Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default putting values into cells is slow

In a program, I have
n=500
application.screenupdating=false
For i=1 to n
cells(i,6).value=cells(i,5).value*35
cells(i+n,6).value=cells(i,4).value*76
next i
application.screenupdating=true

This takes an age to run, especially if n is really large.

There must be a faster (better) way of doing this - can anybody help please?

Thanks
Chris


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default putting values into cells is slow

Chris,

It took less than 1/10 of a second on my xl2002 machine.
Numbers in columns 4 and 5 ran from 10000 to 15000.
There must be something other than the loop causing the hang-up.
'-------------------------
Sub TestLoop()
Dim n As Long
Dim i As Long
Dim StartTime As Single
Dim EndTime As Single
n = 500
Application.ScreenUpdating = False
StartTime = Timer
For i = 1 To n
Cells(i, 6).Value = Cells(i, 5).Value * 35
Cells(i + n, 6).Value = Cells(i, 4).Value * 76
Next i
EndTime = Timer
Application.ScreenUpdating = True
MsgBox EndTime - StartTime & " Seconds"
End Sub
'---------------------------

Jim Cone
San Francisco, USA



"inquirer" wrote in message
...
In a program, I have
n=500
application.screenupdating=false
For i=1 to n
cells(i,6).value=cells(i,5).value*35
cells(i+n,6).value=cells(i,4).value*76
next i
application.screenupdating=true

This takes an age to run, especially if n is really large.

There must be a faster (better) way of doing this - can anybody help please?

Thanks
Chris


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default putting values into cells is slow

Thanks for your reply Jim
I ran the code you sent as is and it took 88.7 seconds.

I am using a Dell 1.8ghz pc with 384MB ram, windows XP SP2. As far as I
know, there are no viruses etc as I regulalry search for them and use a
firewall.

I haven't noticed any other speed problems before this.
Do you have any idea what I might look for to solve the problem?
Chris

"Jim Cone" wrote in message
...
Chris,

It took less than 1/10 of a second on my xl2002 machine.
Numbers in columns 4 and 5 ran from 10000 to 15000.
There must be something other than the loop causing the hang-up.
'-------------------------
Sub TestLoop()
Dim n As Long
Dim i As Long
Dim StartTime As Single
Dim EndTime As Single
n = 500
Application.ScreenUpdating = False
StartTime = Timer
For i = 1 To n
Cells(i, 6).Value = Cells(i, 5).Value * 35
Cells(i + n, 6).Value = Cells(i, 4).Value * 76
Next i
EndTime = Timer
Application.ScreenUpdating = True
MsgBox EndTime - StartTime & " Seconds"
End Sub
'---------------------------

Jim Cone
San Francisco, USA



"inquirer" wrote in message
...
In a program, I have
n=500
application.screenupdating=false
For i=1 to n
cells(i,6).value=cells(i,5).value*35
cells(i+n,6).value=cells(i,4).value*76
next i
application.screenupdating=true

This takes an age to run, especially if n is really large.

There must be a faster (better) way of doing this - can anybody help
please?

Thanks
Chris




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default putting values into cells is slow

I think I know what the problem is.
The test code below ran in 0.9 sec when I opened excel and copied the code
into a new workbook.
When I was running it before, I had another workbook open at the same time.
In this other workbook, I had a column which generated 500 random numbers.
It seems that everytime I ran the test code, the random number generator
must have fired up in the other workbook. I deleted the column which
generated the random numbers and reran the test code - 0.9 sec again.

I don't understand why the random number generator in another open workbook
should be triggered by running the test code. Seems weird to me but at least
I know what causes the slowness.

Chris



"inquirer" wrote in message
...
Thanks for your reply Jim
I ran the code you sent as is and it took 88.7 seconds.

I am using a Dell 1.8ghz pc with 384MB ram, windows XP SP2. As far as I
know, there are no viruses etc as I regulalry search for them and use a
firewall.

I haven't noticed any other speed problems before this.
Do you have any idea what I might look for to solve the problem?
Chris

"Jim Cone" wrote in message
...
Chris,

It took less than 1/10 of a second on my xl2002 machine.
Numbers in columns 4 and 5 ran from 10000 to 15000.
There must be something other than the loop causing the hang-up.
'-------------------------
Sub TestLoop()
Dim n As Long
Dim i As Long
Dim StartTime As Single
Dim EndTime As Single
n = 500
Application.ScreenUpdating = False
StartTime = Timer
For i = 1 To n
Cells(i, 6).Value = Cells(i, 5).Value * 35
Cells(i + n, 6).Value = Cells(i, 4).Value * 76
Next i
EndTime = Timer
Application.ScreenUpdating = True
MsgBox EndTime - StartTime & " Seconds"
End Sub
'---------------------------

Jim Cone
San Francisco, USA



"inquirer" wrote in message
...
In a program, I have
n=500
application.screenupdating=false
For i=1 to n
cells(i,6).value=cells(i,5).value*35
cells(i+n,6).value=cells(i,4).value*76
next i
application.screenupdating=true

This takes an age to run, especially if n is really large.

There must be a faster (better) way of doing this - can anybody help
please?

Thanks
Chris






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default putting values into cells is slow

Reduce your 500 by 50 and run again. Continue to reduce by 50 until
performance improves. You may have to split your routine into two parts.
--
Jim at Eagle


"inquirer" wrote:

Thanks for your reply Jim
I ran the code you sent as is and it took 88.7 seconds.

I am using a Dell 1.8ghz pc with 384MB ram, windows XP SP2. As far as I
know, there are no viruses etc as I regulalry search for them and use a
firewall.

I haven't noticed any other speed problems before this.
Do you have any idea what I might look for to solve the problem?
Chris

"Jim Cone" wrote in message
...
Chris,

It took less than 1/10 of a second on my xl2002 machine.
Numbers in columns 4 and 5 ran from 10000 to 15000.
There must be something other than the loop causing the hang-up.
'-------------------------
Sub TestLoop()
Dim n As Long
Dim i As Long
Dim StartTime As Single
Dim EndTime As Single
n = 500
Application.ScreenUpdating = False
StartTime = Timer
For i = 1 To n
Cells(i, 6).Value = Cells(i, 5).Value * 35
Cells(i + n, 6).Value = Cells(i, 4).Value * 76
Next i
EndTime = Timer
Application.ScreenUpdating = True
MsgBox EndTime - StartTime & " Seconds"
End Sub
'---------------------------

Jim Cone
San Francisco, USA



"inquirer" wrote in message
...
In a program, I have
n=500
application.screenupdating=false
For i=1 to n
cells(i,6).value=cells(i,5).value*35
cells(i+n,6).value=cells(i,4).value*76
next i
application.screenupdating=true

This takes an age to run, especially if n is really large.

There must be a faster (better) way of doing this - can anybody help
please?

Thanks
Chris







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default putting values into cells is slow

Chris,

If you have formulas on the spreadsheet that reference
column 6, then Excel would be attempting to
recalculate the spreadsheet every time a cell changed.

Try adding the following line just below the first screenupdating...
Application.Calculation = xlCalculationManual

Then just before the last screenupdating add...
Application.Calculation = xlCalculationAutomatic

Also, "ActiveSheet.DisplayPageBreaks = False" never hurts.

Regards,
Jim Cone
San Francisco, USA


"inquirer" wrote in message ...
Thanks for your reply Jim
I ran the code you sent as is and it took 88.7 seconds.
I am using a Dell 1.8ghz pc with 384MB ram, windows XP SP2. As far as I
know, there are no viruses etc as I regulalry search for them and use a
firewall.
I haven't noticed any other speed problems before this.
Do you have any idea what I might look for to solve the problem?
Chris



"Jim Cone" wrote in message
...
Chris,
It took less than 1/10 of a second on my xl2002 machine.
Numbers in columns 4 and 5 ran from 10000 to 15000.
There must be something other than the loop causing the hang-up.
'-------------------------
Sub TestLoop()
Dim n As Long
Dim i As Long
Dim StartTime As Single
Dim EndTime As Single
n = 500
Application.ScreenUpdating = False
StartTime = Timer
For i = 1 To n
Cells(i, 6).Value = Cells(i, 5).Value * 35
Cells(i + n, 6).Value = Cells(i, 4).Value * 76
Next i
EndTime = Timer
Application.ScreenUpdating = True
MsgBox EndTime - StartTime & " Seconds"
End Sub
'---------------------------
Jim Cone
San Francisco, USA




"inquirer" wrote in message
...
In a program, I have
n=500
application.screenupdating=false
For i=1 to n
cells(i,6).value=cells(i,5).value*35
cells(i+n,6).value=cells(i,4).value*76
next i
application.screenupdating=true
This takes an age to run, especially if n is really large.
There must be a faster (better) way of doing this - can anybody help
please?
Thanks
Chris


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
taking numbers in vertical cells putting them in horizontal cells jhawk22 Excel Worksheet Functions 4 April 28th 10 08:37 PM
Adding values from 1 workbook based on criteria & putting in anoth Rich Excel Discussion (Misc queries) 0 May 7th 09 08:29 PM
chart keeps putting the values together on same line NocturnalLunacy Excel Discussion (Misc queries) 1 January 6th 09 06:13 PM
Adding values in sheets and putting them on a summery Garry55 Excel Worksheet Functions 2 October 1st 08 03:08 AM
Putting correct values in cells Nick Excel Programming 1 August 26th 04 04:01 PM


All times are GMT +1. The time now is 10:01 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"