|
こんな感じでしょーか ?
Sub MyTime近似値()
Dim Dic As Object
Dim Myk As Variant, MyIt As Variant
Dim i As Long, Ary(0 To 2) As Long
Dim Mi As Long, Num As Long
Dim GetTm As Date
Set Dic = CreateObject("Scripting.Dictionary")
With Dic
.Add "13:00", "100"
.Add "12:00", "450"
.Add "9:00", "300"
Myk = .Keys: MyIt = .Items
End With
For i = 0 To Dic.Count - 1
Mi = Abs(Val(MyIt(i)) - 290)
Ary(i) = Mi
Next i
With WorksheetFunction
Num = .Match(.Min(Ary), Ary, 0) - 1
End With
GetTm = TimeValue(Myk(Num))
MsgBox "近似値は " & GetTm
Set Dic = Nothing: Erase Ary
End Sub
|
|