I want the following solution in Excel VBA The file Stock Prices.xlsx contains m
ID: 3677918 • Letter: I
Question
I want the following solution in Excel VBA
The file Stock Prices.xlsx contains monthly adjusted closing prices, adjusted
for dividends and stock splits, for WalTech’s stock from 2003 to early 2011.
(WalTech is a fictitious company.)
a. Write a sub called RecordHigh1 that takes a single argument called search-
Price. This sub searches down the list of prices for the first price that exceeds
the searchPrice argument. If it finds one, it displays the corresponding date
in a message, something similar to, “The first date WalTech stock price
exceeded _ was _.” If the price never exceeded the argument searchPrice, it
displays a message to this effect. Next, write a Records sub that uses an input
box to ask the user for a price and then calls RecordHigh1 with this price as
the argument.
Explanation / Answer
Sub RecordHigh1(ByVal searchPrice As Double)
Dim D As Date
For i = 1 To Range("B1").End(xlDown).Row
If Range("B" & i) > searchPrice Then
' This way i search a date range rather than a specific date
D = Range("A" & i).Value
MsgBox ("The first date WalTech stock price exceeded " & Range("B" & i) & " was " & D)
End
End If
Next
MsgBox ("Stock price does not exceed the given")
End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.