如果已知行和列,则在表中查找值

时间:2014-08-19 12:59:32

标签: excel-vba vba excel

     V1   V2   V3

A    1    5     9

B    2    2     6

C    7    8     4

如何使用行和列标题找到V2B,V1A等中存在的值。例如,如果我选择V2B,它应该返回值2,依此类推......

1 个答案:

答案 0 :(得分:0)

找到正确的列和正确的行并将它们相交:

Sub tabLookup()
    Dim v1 As String, v2 As String
    Dim r1 As Range, r2 As Range
    v1 = "V1"
    v2 = "A"
    Set r1 = Cells.Find(what:=v1).EntireColumn
    Set r2 = Cells.Find(what:=v2).EntireRow
    MsgBox Intersect(r1, r2).Value
End Sub