VBA中的一系列单元格引用和值查找

时间:2015-10-22 17:04:47

标签: vba

我需要一个从多个单元格中查找多个值的UDF。应该通过它们与调用UDF的单元格的偏移量找到单元格。

到目前为止,我总是得到#value

Function Test() As Integer
    Dim OwnCell As Range
    Dim Total As Range
    Dim Val As Integer
    Set OwnCell = Application.ThisCell.Address
    Set Total = OwnCell.Offset(13, -4)
    Val = Worksheets("Blad1").Range(Total).Value
    Test = Val
End Function

管理使其“工作”#34;但它似乎非常不优雅:

Function Test() As Integer
    Dim OwnCell As String
    Dim Total As String
    Dim TotalVal As Integer
    OwnCell = Application.ThisCell.Address
    Total = Range(OwnCell).Offset(1, 1).Address
    TotalVal = Worksheets("Blad1").Range(Total).Value
    Test = Val
End Function

1 个答案:

答案 0 :(得分:0)

除非返回的单元格实际上与输入UDF的单元格不同,否则这应该有效:

$( this ).parent()