2013-05-08 99 views
1

需要VBA Sub根据行和列ID找到单元格值。 在下面的例子中,我需要选择其中东和RT3交叉而80如何根据excel中的行和列ID找到单元格值VBA

 
    A B C D E 
1 null RT1 RT2 RT3 RT4 
2 North 31 40 78 11 
3 South 32 41 79 12 
4 East 33 42 80 13 
5 West 34 43 81 14 
+2

您可以用'find()'在列/行头,以确定您需要的行和列,然后使用指标细胞'细胞(行,列)' – 2013-05-09 00:15:02

回答

-1

有不同的方法可以做到这一点,但一个方法是使用一个函数的参数值。你没有说你是如何传递参数的,所以我只是用一个sub来调用这个函数。

Function GetValue(row As Integer, col As Integer) 
    GetValue = ActiveSheet.Cells(row, col) 
End Function 

Sub CallGetValue() 
    Dim cellval As String 
    cellval = GetValue(row:=4, col:=4) 
    MsgBox (cellval) 
End Sub 
+0

我不认为这是OP所寻求的 - 他正在寻找一个使用'东'和'RT3'作为输入来识别行和列的例程... – 2014-02-14 07:01:13

3

使用类似下面没有测试

Function getcell(ct as string, rt as string) as range 

    With activecell 
     R = .columns("A").find(rt).row 
     C = .rows("1").find(ct).Column 
     'The below will escape the function if none where found 
     If r = nothing or c = nothing then exit function 
     Set getcell = .cells(r, c) 
    End with 

End function 
+0

它看起来不错但是当我尝试调用该函数时,我得到了模糊名称错误。 – herrtodd33 2013-05-20 17:12:18

+0

可能应该是'activesheet'。 – glh 2013-05-21 14:08:09

+0

Humm。仍然收到与第一行相关的错误“Function getcell(ct as string,rt as string)as range”您能够成功调用函数吗? – herrtodd33 2013-05-21 14:58:33

相关问题