Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

in VBA what steps do i take to: Insert a button which prompts the user for weigh

ID: 2799647 • Letter: I

Question

in VBA what steps do i take to:

Insert a button which prompts the user for weights for each stock. Use VBA to input the user’s weights into the cells that contain the weights (F4:F8). • If the weights add up to more than 100%, output a message telling the user that no leverage is allowed and that he/she must re-enter the weights. • If the weights add up to less than 100%, output a message that tells the user that she/he must be fully invested, and ask the user to re-enter the weights. • Use the weights that are given in the spreadsheet as the default values for each stock.

Explanation / Answer

Sub weightstock()
a = CDbl(InputBox("Ënter the weight of stock1", Default, Range("F4").Value))
b = CDbl(InputBox("Ënter the weight of stock2", Default, Range("F5").Value))
c = CDbl(InputBox("Ënter the weight of stock3", Default, Range("F6").Value))
d = CDbl(InputBox("Ënter the weight of stock4", Default, Range("F7").Value))
e = CDbl(InputBox("Ënter the weight of stock5", Default, Range("F8").Value))

If (a + b + c + d + e) < 1 Then
MsgBox ("You must be fully invested.Please re-enter the weights")
weightstock
ElseIf (a + b + c + d + e) > 1 Then
MsgBox ("No leverage is allowed.Please re-enter the weights")
weightstock
End If
Range("F4") = a
Range("F5") = b
Range("F6") = c
Range("F7") = d
Range("F8") = e

End Sub