0

我有以下 2 张桌子(赔率和投注)。

表格1

表格1

表 2:

表 2

我想将表 2 中的 TransId 与表 1 中的 TransId 进行比较,并检索一些值并将其粘贴到表 2 的价格列中。我的 VBA 代码中有一个 VLOOKUP 函数来完成这项工作。然而,它遍历第一列(oddsId)并因此获取错误的价格(希望这是预期的,因为 Vlookup 总是寻找最左边的列,如果我没有错的话)。

但我想比较两个 TransId 以获取价格信息。

价格列使用公式:

=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 函数)中处理这种情况。有没有办法解决这个问题?

4

1 回答 1

0

通过删除第一列计算 VLookup 使用的范围。

dim odds_range as range
with Range("OddsTable5")
  set odds_range = Range( .Cells(1,2), .Cells(.Rows.Count, .Columns.Count) )
end with

...

GetPrice = Application.WorksheetFunction.VLookup(transId, odds_range, 14, False)
于 2013-09-29T08:39:52.167 回答