次の 2 つのテーブル (オッズとベット) があります。
表1
表 2:
テーブル 2 の TransId とテーブル 1 の TransId を比較し、いくつかの値を取得して、同じ値をテーブル 2 の Price 列に貼り付けたいと考えています。この作業を行うために、VBA コードに VLOOKUP 関数があります。ただし、最初の列 (oddsId) を反復処理するため、間違った価格をフェッチします (間違っていなければ、Vlookup は常に左端の列を探すため、これが予想されることを願っています)。
しかし、両方の TransId を比較して価格情報を取得したいと考えています。
Price 列は次の式を使用します。
=getprice(BetsTable[[#This Row],[TransId]],BetsTable[[#This Row],[Option]])
以下は、GetPrice のコード サンプルです。
Function GetPrice(transId, opt)
Dim bettype As String
opt = UCase(opt)
bettype = Application.WorksheetFunction.VLookup(transId, Range("OddsTable5"), 3, False)
If (bettype = "FT.HDP" Or bettype = "HT.HDP") Then
If (opt = "H") Then
GetPrice = Application.WorksheetFunction.VLookup(transId, Range("OddsTable5"), 14, False)
ElseIf (opt = "A") Then
GetPrice = Application.WorksheetFunction.VLookup(transId, Range("OddsTable5"), 15, False)
Else
GetPrice = "Error"
End If
この状況を VBA コード (getPrice 関数) で処理したいと考えています。この問題を解決する方法はありますか?