Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Insert calculation with VBA is slow

Hi all, i have a spread sheet that i have to insert two calculations in,
in columns "I" & "J" and i am doing it by looping down the sheet as the
length is variable, sometimes 100 rows and sometimes 10,000 rows !! My
question is, is there a quicker way to do this, as when you get to the
bigger spread sheet it takes quite long ?

Best regards,

Les Stout


*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Insert calculation with VBA is slow


Hey there,

Of course, looping down is the easiest way, so why shouldn't you go
it.

so while the stopcondition is false do
Insert the formulae or values into the cells I&J of the current
column
increment the rowindex
loop

That was the slow way, to make excel calculate much faster, we're now
going to deactivate calculation and screenupdating, while inserting.

The Code will look like:

Code:
--------------------
rowindex=1
application.screenupdating=false
application.calculation = xlManual
On Error goto Resetting
while ([stop_condition])
Cells(rowindex,9)="I"
Cells(rowindex,10)="J"
rowindex = rowindex + 1
loop

Resetting:
Application.screenupdating = true
Application.calculation= xlAutomatic

--------------------



Regards,

Simon


--
moondark
------------------------------------------------------------------------
moondark's Profile: http://www.excelforum.com/member.php...o&userid=27390
View this thread: http://www.excelforum.com/showthread...hreadid=475759

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Insert calculation with VBA is slow

Hi Les,

Try something like:

'=============
Public Sub TryIt()
Dim rng As Range
Dim Lrow As Long
Dim CalcMode As Long
Const col As String = "I" '<<== CHANGE

Lrow = Cells(Rows.Count, col).End(xlUp).Row

On Error GoTo XIT

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

Set rng = Range(col & "2:" & col & Lrow)
With rng
.FormulaR1C1 = "=SUM(RC[1]:RC[3])" '<<== CHANGE
.Offset(0, 1).FormulaR1C1 = _
"=SUM(RC[5]:RC[7])" '<<== CHANGE
End With

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

---
Regards,
Norman


"Les Stout" wrote in message
...
Hi all, i have a spread sheet that i have to insert two calculations in,
in columns "I" & "J" and i am doing it by looping down the sheet as the
length is variable, sometimes 100 rows and sometimes 10,000 rows !! My
question is, is there a quicker way to do this, as when you get to the
bigger spread sheet it takes quite long ?

Best regards,

Les Stout


*** Sent via Developersdex http://www.developersdex.com ***



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Insert calculation with VBA is slow

Hi Les,

Set rng = Range(col & "2:" & col & Lrow)

Change 2 to the first formula insertion row.

---
Regards,
Norman


"Norman Jones" wrote in message
...
Hi Les,

Try something like:

'=============
Public Sub TryIt()
Dim rng As Range
Dim Lrow As Long
Dim CalcMode As Long
Const col As String = "I" '<<== CHANGE

Lrow = Cells(Rows.Count, col).End(xlUp).Row

On Error GoTo XIT

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

Set rng = Range(col & "2:" & col & Lrow)
With rng
.FormulaR1C1 = "=SUM(RC[1]:RC[3])" '<<== CHANGE
.Offset(0, 1).FormulaR1C1 = _
"=SUM(RC[5]:RC[7])" '<<== CHANGE
End With

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<=============

---
Regards,
Norman


"Les Stout" wrote in message
...
Hi all, i have a spread sheet that i have to insert two calculations in,
in columns "I" & "J" and i am doing it by looping down the sheet as the
length is variable, sometimes 100 rows and sometimes 10,000 rows !! My
question is, is there a quicker way to do this, as when you get to the
bigger spread sheet it takes quite long ?

Best regards,

Les Stout


*** Sent via Developersdex http://www.developersdex.com ***





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Insert calculation with VBA is slow

Thanks Norman.

best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Insert calculation with VBA is slow

Thanks Simon, alais moondark will also save this for my macro database.

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
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
Slow Calculation Vanessa Simmonds Excel Discussion (Misc queries) 1 November 24th 08 03:00 PM
worksheet very slow in calculation Deepak G New Users to Excel 4 August 22nd 08 02:12 PM
Slow Calculation JavyD Excel Worksheet Functions 2 May 16th 06 10:50 PM
Does this slow down calculation? sfrancoe Excel Discussion (Misc queries) 1 January 15th 06 03:39 PM
Slow calculation Eva Shanley[_2_] Excel Programming 0 July 2nd 04 01:20 PM


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