从=选择函数获取当前单元格

时间:2014-02-10 11:59:19

标签: excel vba excel-vba

我有一个带有选择功能的单元格

=CHOOSE(A3;Food!$J$2;Food!$K$2;Food!$L$2;Food!$M$2;Food!$N$2;Food!$O$2;Food!$P$2;Food!$Q$2;Food!$R$2;Food!$S$2;Food!$T$2;Food!$U$2;Food!$V$2;Food!$W$2;Food!$X$2;Food!$Y$2;Food!$Z$2;Food!$AA$2;Food!$AB$2;Food!$AC$2;Food!$AD$2;Food!$AE$2;Food!$AF$2;Food!$AG$2;Food!$AH$2;Food!$AI$2;Food!$AJ$2;Food!$AK$2;Food!$AL$2;Food!$AM$2;)

在另一个单元格中,我想要接收选择函数现在引用的单元格的地址

如果索引是1我想获得Food!$J$2,或者索引是3我想获得Food!$L$2等等

如何用vba解决这个问题?

2 个答案:

答案 0 :(得分:0)

为什么这样做?你为什么不这样做:

=INDEX(Food!$J$2:$AM$2;1;A3)

答案 1 :(得分:0)

撤消所需物品的顺序:

首先获取单元格地址,然后获取内容。所以在A4中输入:

=CHOOSE(A3,"Food!$J$2","Food!$K$2","Food!$L$2","Food!$M$2","Food!$N$2","Food!$O$2","Food!$P$2","Food!$Q$2","Food!$R$2","Food!$S$2","Food!$T$2","Food!$U$2","Food!$V$2","Food!$W$2","Food!$X$2","Food!$Y$2","Food!$Z$2","Food!$AA$2","Food!$AB$2","Food!$AC$2","Food!$AD$2","Food!$AE$2","Food!$AF$2","Food!$AG$2","Food!$AH$2","Food!$AI$2","Food!$AJ$2","Food!$AK$2","Food!$AL$2","Food!$AM$2")

并在A5中输入:

=INDIRECT(A4)

如果你真的要求VBA使用类似的东西:

Sub dural()
    Dim s As String, Indx As Long
    s = Range("A4").Formula
    ary = Split(s, ",")
    Indx = Range("A3")
    MsgBox ary(Indx)
End Sub