<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Does anyone know what this code is doing?' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Does anyone know what this code is doing?' posted on the 'VBA' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2010 Programmers Heaven</copyright>
    <pubDate>Wed, 17 Mar 2010 16:31:09 -0700</pubDate>
    <lastBuildDate>Wed, 17 Mar 2010 16:31:09 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Does anyone know what this code is doing?</title>
      <link>http://www.programmersheaven.com/mb/vba/409934/409934/does-anyone-know-what-this-code-is-doing/</link>
      <description>Hi guys.&lt;br /&gt;
&lt;br /&gt;
I am pmmd861, I am new here. Nice to meet you all!&lt;br /&gt;
&lt;br /&gt;
Could anyone help me with this VBA Excel code, please?&lt;br /&gt;
&lt;br /&gt;
So, i ve got the excel spreadsheet from someone else, and i need to nuderstand the code there so that i could slightly rebuild it in the future. I understand everything in the code, but there is some piece of code that i ve never seen and i have no idea how it works! &lt;br /&gt;
&lt;br /&gt;
Here is the extract from the program.&lt;br /&gt;
&lt;br /&gt;
In the Calibrate sub i have the code&lt;br /&gt;
&lt;br /&gt;
    &lt;pre class="sourcecode"&gt;
Sheets("EL 1").Select
    Range("H9").Select
    ActiveCell.FormulaR1C1 = "1"
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
This bit is simple.&lt;br /&gt;
&lt;br /&gt;
But when &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;ActiveCell.FormulaR1C1 = "1"&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
is executed the code changes the value in the cell H9 AND after that CALLS the user defined FUNCTION in another module! My question is WHY? This is not how you call the function, right? Does it have something to do with windows programming language (i think it called API functions)? &lt;br /&gt;
&lt;br /&gt;
Also, it repeats the function many times, as if it is driven by some external loop (but there is no any cpde the loop).&lt;br /&gt;
&lt;br /&gt;
I tried to delete ALL the code in ALL modules and just to leave this bit - it still call the function in the same way. &lt;br /&gt;
&lt;br /&gt;
Also, there ii the same code for another sheet, but on that sheet  when one cell is changes it calls the functuion and when another cell is changed it does NOT call this function? PLease, give me a hint where to look for the answer! I searched for Application. properties in the code and in the ThisWorkbook module and didnt find anything! Also, there no any classes in this project.&lt;br /&gt;
&lt;br /&gt;
Does this behaviour resemble something that you know?&lt;br /&gt;
&lt;br /&gt;
The function that is called is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;Function fnRiskWeightedAssetsCardsOvers(EAD As Double, LGD As Double, PD As Double) As Double
    
    On Error GoTo Err_fnRiskWeightedAssetsCardsOvers
    
    Dim K As Double
    
    K = fnCapitalReqCardsOver_K(LGD, PD)
    
    fnRiskWeightedAssetsCardsOvers = K * 12.5 * EAD
    
    Exit Function

Err_fnRiskWeightedAssetsCardsOvers:
    
     fnRiskWeightedAssetsCardsOvers = 0

End Function

Function fnRiskWeightedAssetsLoans(EAD As Double, LGD As Double, PD As Double) As Double
    
    On Error GoTo Err_fnRiskWeightedAssets
    
    Dim K As Double
    
    K = fnCapitalReqLoans_K(LGD, PD)
    
    fnRiskWeightedAssetsLoans = K * 5 * EAD
    
    Exit Function

Err_fnRiskWeightedAssets:
    
     fnRiskWeightedAssetsLoans = 0

End Function
 
Function fnCapitalReqCardsOver_K(LGD As Double, PD As Double) As Double

    With WorksheetFunction
        fnCapitalReqCardsOver_K = LGD * Sqr(0.25) - PD * LGD
    End With

End Function

Function fnCapitalReqLoans_K(LGD As Double, PD As Double) As Double

    With WorksheetFunction
        fnCapitalReqLoans_K = LGD * .NormSDist(1 / Sqr(1 - Corr(PD)) - PD * LGD
    End With

End Function

Function fnPDLoans(PD As Double) As Double

    With WorksheetFunction
        fnPDLoans = .NormSDist(1 / Sqr(1 - Corr(PD)) * .NormSInv(PD) + Sqr(Corr(PD)) / Sqr(1 - Corr(PD)) * .NormSInv(0.999)) - PD
    End With

End Function

Function Corr(PD As Double) As Double
    Corr = (1 - Exp(-35 * PD)) / (1 - Exp(-35))

End Function&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Thankx for your help guys!&lt;br /&gt;
&lt;br /&gt;
pmmd861&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/vba/409934/409934/does-anyone-know-what-this-code-is-doing/</guid>
      <pubDate>Fri, 27 Nov 2009 07:05:42 -0700</pubDate>
      <category>VBA</category>
    </item>
  </channel>
</rss>