0% found this document useful (0 votes)
10 views4 pages

VBA

The document contains several VBA subroutines for financial calculations, including future value of loans, tax rate determination based on income, and deposit growth over time. Each subroutine prompts the user for input and displays the results using message boxes. There are also examples of looping structures to calculate the number of years required to reach a financial target.

Uploaded by

Linh Ánh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

VBA

The document contains several VBA subroutines for financial calculations, including future value of loans, tax rate determination based on income, and deposit growth over time. Each subroutine prompts the user for input and displays the results using message boxes. There are also examples of looping structures to calculate the number of years required to reach a financial target.

Uploaded by

Linh Ánh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Sub practice_2()

Dim loan_type As String


Dim loan_amount As Double
Dim interest_rate As Double
Dim num_year As Interior

loan_type = "Bullet loan"


loan_amount = 100000
interest_rate = 0.03
num_years = 10

future_value = loan_amount * (1 + interest_rate) ^ num_years


MsgBox future_value
End Sub
Sub practice_3()
loan_type = InputBox("Please enter the type of loan")
loan_amount = InputBox("Please enter the loan amount")
interest_rate = InputBox("Please enter the interest rate")
num_years = InputBox("Enter the number of years")

future_value = loan_amount * (1 + interest_rate) ^ num_years


MsgBox future_value
End Sub
Sub CountSheets()
Dim Item As Worksheet
For Each Item In ActiveWorkbook.Worksheets
MsgBox Item.Name
Next Item
End Sub
Sub practice_4()
income = InputBox("Enter your acccessable income")

If income < 5 Then


tax_rate = 0.05
ElseIf income < 10 Then
tax_rate = 0.1
ElseIf income < 18 Then
tax_rate = 0.15
ElseIf income < 32 Then
tax_rate = 0.2
ElseIf income < 52 Then
tax_rate = 0.25
ElseIf income < 80 Then
tax_rate = 0.3
Else
tax_rate = 0.35
End If

MsgBox tax_rate
End Sub
Sub practice_5()
income = InputBox("Enter your acccessable income")

Select Case income


Case Is < 5: tax_rate = 0.05
Case Is < 10: tax_rate = 0.1
Case Is < 18: tax_rate = 0.15
Case Is < 32: tax_rate = 0.2
Case Is < 52: tax_rate = 0.25
Case Is < 80: tax_rate = 0.3
Case Else: tax_rate = 0.35
End Select
MsgBox tax_rate
End Sub
Sub practice_6()
deposit = InputBox("Enter the amount of deposit")
num_years = InputBox("Enter the number of years")
interest_rate = InputBox("Enter the annual interest rate")
future_value = deposit
Count = 1
For Count = 1 To num_years
deposit = deposit * (1 + interest_rate)
Next Count
MsgBox "You would get $" & Round(deposit, 2) & _
" after " & num_years & " years "
End Sub
Sub practice_7()
Dim deposit As Double
Dim target As Double
Dim interest_rate As Double

deposit = InputBox("Enter the amount of deposit")


target = InputBox("Enter your target")
interest_rate = InputBox("Enter interest rate")
num_year = 0
Do While deposit <= target
deposit = deposit * (1 + interest_rate)
num_year = num_year + 1
Loop
MsgBox num_year
End Sub
Sub practice_8()
Dim deposit As Double
Dim target As Double
Dim interest_rate As Double

deposit = InputBox("Enter the amount of deposit")


target = InputBox("Enter your target")
interest_rate = InputBox("Enter interest rate")
num_year = 0
Do until >= target
deposit = deposit * (1 + interest_rate)
num_year = num_year + 1
Loop
MsgBox num_year
End Sub

You might also like