View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
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 ***