LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Manual Calculation Problem

I am currently writing a simulation program using excel. The following
code has worked fine in the past but now doesn't want to calculate in
manual mode for some strange reason. Can somebody spot a stupid error
here ? The code works fine in semiautomatic and automatic mode but
takes 4 times as long to calculate :(
Sub RunSimulation()
'Transactor.Hide
Dim termOfLoan
Dim g As Range
Dim LGD_DEFQ
Dim ELLterm
Dim ELL
Dim graceQs As Integer
Dim sourceRange As Range
Dim fillRange As Range
Dim lossRange As Range

Workbooks("Frontend1.xls").Sheets("TMMlnResult").A ctivate
Application.ScreenUpdating = False
'Delete the values from the previous simulation
Range("BZ10:CA5010").ClearContents
Range("B21:BA5021").ClearContents
Range("BB22:BG396").ClearContents
Range("CA10:CA65000").ClearContents

'read in the constants
ELLterm = Evaluate(ActiveWorkbook.Names("ELLterm").RefersTo)
ELL = Evaluate(ActiveWorkbook.Names("ELL").RefersTo)
LGD_DEFQ = Workbooks("Frontend1.xls").Sheets("PortfolioManage r").Range("G17").Value
termOfLoan = Workbooks("Frontend1.xls").Sheets("AUTO-INPUT").Range("B26").Value
+ (Workbooks("Frontend1.xls").Sheets("AUTO-INPUT").Range("B26").Value
/ 4)
graceQs = Workbooks("Frontend1.xls").Sheets("AUTO-INPUT").Range("B16").Value

'Set the term of the loan introducing defered quarters and grace
quarters for LGD
If ELL Then
termOfLoan = ELLterm * 4 + 6 + LGD_DEFQ + graceQs
Else
termOfLoan = termOfLoan * 4 + 6 + LGD_DEFQ + graceQs
End If

str12 = "4:" & termOfLoan
str13 = "4:" & termOfLoan + 1

Application.Calculation = xlManual
Application.EnableEvents = False
'Show progress bar
frmProgress.progbar.Max =
Workbooks("Frontend1.xls").Sheets("TMMlnResult").R ange("C1").Value
str = "Transactor is performing simulation." & vbLf & "Please
wait...."
frmProgress.lblProg.Caption = str
DoEvents
Workbooks("Frontend1.xls").Activate
'take the user set number of iterations in future
For i = 1 To Sheets("TMMlnResult").Range("C1").Value
frmProgress.progbar.Value = i

Sheets("MRPs").UsedRange.Rows(str12).Calculate
Sheets("SVgen").Columns("L:U").Calculate
Sheets("LoanCalc Q").UsedRange.Rows(str13).Calculate
Sheets("TMMlnResult").UsedRange.Rows("14:16").Calc ulate

Sheets("TMMlnResult").Range("B20:BA20").Offset(i, 0).Value = _
Sheets("TMMlnResult").Range("B15:BA15").Value
Next



Workbooks("Frontend1.xls").Activate
Set fillRange = Workbooks("Frontend1.xls").Sheets("TMMlnResult").R ange("BB21:BG396")
Set sourceRange =
Workbooks("Frontend1.xls").Sheets("TMMlnResult").R ange("BB21:BG21")
sourceRange.AutoFill Destination:=fillRange, Type:=xlFillValues
Set lossRange = Workbooks("Frontend1.xls").Sheets("TMMlnResult").R ange("B21:AY5021")
i = 0
'Reset progress bar for next stage
frmProgress.lblProg.Caption = "Calculating PDs and LGDs from
simulation results."
frmProgress.progbar.Value = 0
frmProgress.progbar.Max = lossRange.count

Application.ScreenUpdating = True
For Each g In lossRange.Cells
frmProgress.progbar.Value = frmProgress.progbar.Value + 1
If CSng(g.Value) = 0.0001 Then
i = i + 1
If CSng(g.Value) < 1 Then
Sheets("TMMlnResult").Range("CA9").Offset(i, 0).Value
= g.Value
Else
Sheets("TMMlnResult").Range("CA9").Offset(i, 0).Value
= CSng(g.Value) - 1
End If
End If
Next g


Worksheets("output").Calculate
Sheets("output").Range("D60:I60").Value =
Sheets("output").Range("D36:I36").Value
Application.Calculation = xlCalculationAutomatic

Application.EnableEvents = True
End Sub

Sorry for the long post but I really need to fix this

Regards
Nigel Brown
Theisen Securities
 
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
Can I add to a cell value without manual calculation? Brian Excel Discussion (Misc queries) 1 March 31st 10 01:09 PM
Calculation Manual vs Automatic TJAC Excel Discussion (Misc queries) 3 March 4th 08 10:13 PM
Manual Calculation TeresaD Setting up and Configuration of Excel 7 January 28th 08 08:54 PM
Calculation - Automatic and Manual shepcon Excel Discussion (Misc queries) 1 July 17th 07 05:14 PM
Calculation set as Manual Dan. Excel Discussion (Misc queries) 1 February 14th 06 04:30 PM


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