|
补上代码
- Sub Find_Rate()
- Dim t
- Dim arr
- Dim m As Integer
- Dim s_Stock As String
- Dim d_Trans As Date
- Dim s_Rate As String
- t = Timer
- arr = Sheets("bond").UsedRange
- With Sheets("yield")
- For m = 2 To .Cells(65536, 1).End(xlUp).Row
- s_Stock = .Cells(m, 1) 'Stock Number
- d_Trans = .Cells(m, 2) 'Transaction Date
- s_Rate = Lookup_Data_by_Array(arr, s_Stock, d_Trans)
- .Cells(m, 3) = s_Rate
- Next m
- End With
- MsgBox (Timer - t)
- End Sub
- Function Lookup_Data_by_Array(arr, Str$, Dt) As String
- Dim i, j
- Dim iStock As String
- Dim iDate As Date
- Dim flag As Boolean
- For i = 2 To UBound(arr)
- iStock = arr(i, 1)
- If iStock = Str Then 'Stock Number Matched
- flag = True
- j = i
- Do While flag
- If j > UBound(arr) Then Lookup_Data_by_Array = "NA": Exit Function
- iDate = arr(j, 2)
- If Dt < iDate Then
- flag = False
- Lookup_Data_by_Array = arr(j, 3)
- Exit Function
- Else
- j = j + 1
- End If
- Loop
- End If
- Next i
- End Function
复制代码 |
|