# VBA_Codes - Compound Interest Code Sub CompInt'declare...

• 7
• 86% (7) 6 out of 7 people found this document helpful

This preview shows page 1 - 4 out of 7 pages.

Compound Interest Code Sub CompInt() 'declare variables Dim D As Currency Dim R As Double Dim N As Integer Dim B As Currency 'input D = Range("B2").Value R = Range("B3").Value N = Range("B4").Value 'process B = D * (1 + R) ^ N 'output Range("B5").Value = B End Sub Beefnut Flow Chart Code Sub BeefNut() 'declare variables Dim NOD As Integer Dim Bill As Currency Dim price As Currency Dim threshold As Integer 'input NOD = Range("B1").Value threshold = Range("B5").Value 'process (set price) If NOD < threshold Then price = Range("B4").Value Else price = Range("B3").Value End If 'calculate bill Bill = price * NOD 'output Range("B2").Value = Bill End Sub
Engineering Flow Chart Sub Duct() 'declare variables Dim doesItMove As String Dim shouldIt As String Dim solution As String 'inputs - lcase(string)helps us ignore case doesItMove = LCase(Range("B1").Value) shouldIt = LCase(Range("B2").Value) 'process - oh the tough decisions engineers have to make If doesItMove = "yes" Then If shouldIt = "yes" Then solution = "no problem" Else solution = "use duct tape" End If ElseIf shouldIt = "yes" Then solution = "WD-40" Else solution = "no problem" End If 'output Range("B3").Value = solution End Sub Guessing Game Sub guessingGame() 'declare variables Dim theNumber As Integer Dim theGuess As Integer 'input theNumber = WorksheetFunction.RandBetween(1, 10) Do 'start game 'ask for input theGuess = InputBox("I'm thinking of a number between 1 and 10. What is it?") 'process If theNumber = theGuess Then MsgBox ("Wahoo! You guessed it!") Exit Do 'done
ElseIf theGuess > theNumber Then MsgBox "Lower!"