【发布时间】:2023-04-03 11:56:01
【问题描述】:
我需要编写一个从输入框中获取单个参数的子程序,该输入框在列表中搜索股票价格。子搜索从“B3:B20”开始的价格列表,当它找到超过这个价格的第一个价格时,它会在 msgbox 的 A 列中显示在它旁边的列中显示的日期。这是我到目前为止的代码,但我无法弄清楚如何显示找到的价格的相应数据:(我相信问题与创建的数组有关)
Sub RecordHigh1()
Dim searchPrice As Currency
Dim rng As Range
Dim date1() As String
Dim price() As String
Dim nDates As Integer
Dim i As Integer
With wsData.Range("A3")
nDates = Range("A3", Range("A3").End(xlDown).Value)
ReDim date1(1 To nDates)
ReDim price(1 To nDates)
For i = 1 To nDates
date1(i) = .Offset(i, 0).Value
price(i) = .Offset(i, 1).Value
Next
End With
searchPrice = InputBox("Enter a Price")
Set rng = Range("B3", Range("B3").End(xlDown).Address)
For Each cell In rng
If cell.Value > searchPrice Then
MsgBox "The first date WalTech stock price exceeded " & searchPrice & " was & date(i) =.Offset(i, 0).Value & "
Else
MsgBox "WalTech stock has not exceeded this price"
End If
Next
End Sub
【问题讨论】:
-
您缺少
"所以searchPrice & " was & date(i)应该是searchPrice & " was " & date(i)并且末尾的和号和双引号需要删除。 -
@JerryJeremiah 代码仍然无法工作
-
@th65 - 代码在哪一行中断?