View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Advice on optimizing spreadsheet

I think in this particular case there won't be much difference in speed, but
doing this is VBA
is a lot neater, will make the workbook a lot smaller and will make it
easier to optimize for speed.
Only some testing will tell you what the speeds will be:

Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private lStartTime As Long

Sub StartSW()
lStartTime = timeGetTime()
End Sub

Sub StopSW(Optional ByRef strMessage As Variant = "")
MsgBox "Done in " & timeGetTime() - lStartTime & " msecs", , strMessage
End Sub

Sub test()

'Application.Calculation = xlCalculationManual
Application.Calculation = xlCalculationAutomatic

StartSW

Cells(14, 13).Value = 0

Application.Calculate

StopSW

End Sub

Sub test2()

Dim dVal1 As Double
Dim dVal2 As Double
Dim dVal3 As Double
Dim arr
Dim i As Long

Cells(14, 13).Value = 2

dVal1 = Cells(14, 13).Value
dVal1 = Cells(15, 13).Value
dVal1 = Cells(17, 13).Value

arr = Range(Cells(1), Cells(10000, 3))

StartSW

For i = 1 To 10000
If arr(i, 1) < "" Then
If arr(i, 1) <= dVal1 Then
arr(i, 1) = 0
Else
If arr(i, 1) = dVal2 Then
arr(i, 1) = dVal3
Else
arr(i, 1) = arr(i, 1) - dVal1
End If
End If
End If
Next i

StopSW

End Sub


RBS


"schizoid_man" wrote in message
ps.com...
Hi,

I have a spreadsheet that has multiple rows (10000) with several
compound If statements throughout one sheet of my workbook. An example
of such a statement is:
IF(C2<"",IF(C2<=$M$14,0,IF(C2=$M$15,$M$17,C2-$M$14)),"")

My question is: would it be faster for me to remove all the If
statements from this sheet and simply write a VBA subroutine that
would do the same thing?

I'm certain that it would make the spreadsheet more compact, but would
it improve performance?

I'm writing a Monte-Carlo simulation so performance is paramount for
me.

Thanks.