如何将动态值传递给Excel中的INDEX函数?

huangapple go评论52阅读模式
英文:

How pass dynamic value to a INDEX function in Excel?

问题

我想编写一个动态的Excel条件来基于单元格内容获取一些值。

我的Excel工作表包含3个标签:Hometab_1tab_2。在home标签中,我有一些文本内容用于选择sheettable

tab_1工作表中,我有名为Table_1Table_2Table_3Table_4的表格。

现在我想根据文本值从表格中获取一些元素。

**示例:**如果标签名称为Tab_1,表格名称为Table_1,那么我将从Tab_1工作表中的Table_1数组中获取第2个索引值。

我的计划是使用Excel公式来实现动态操作。

因此,我尝试编写以下逻辑以获取第2个索引值。

INDEX(INDIRECT("' "&$B$2&" '!B1:F1"),2)

在这里,它将把$B2作为Tab_1。我将表格值传递为'B1:F1'

现在,我不知道如何获取主工作表(Home标签)中的单元格$B3与表格Table_1匹配的数组(而不是B1:F1)。

有什么建议或帮助吗?

英文:

I want to write a dynamic excel condition to fetch some values based on the cell Contents.

My excel sheet contain 3 tabs. Home, tab_1 and tab_2 respectively. In the home tab, I have some text contents for selecting sheet and table.

如何将动态值传递给Excel中的INDEX函数?

In the tab_1 sheet, i have tables named as Table_1, Table_2,Table_3 and Table_4.

如何将动态值传递给Excel中的INDEX函数?

Now I want to get some elements from the table based on the text values.

Example: if the sheet name = Tab_1 and Table name = Table_1 then i will take the 2nd index values from Table_1 array in Tab_1 sheet.
My plan is to do dynamically using excel formula.

So i have tried to write the below logic to get 2nd index values.

INDEX(INDIRECT("'"&$B$2& "'!B1:F1"),2) 

here it will take $B2 as Tab_1 . I am passing table value as "B1:F1".

Now i don't know how to get the matching array (instead of B1:F1) with the cell $B3 in the home sheet (Table_1).

Any suggestion or help ?

答案1

得分: 0

Finally after some research, I found the solution. We can use MATCH function to check the exact row name.

INDIRECT("'"&$B$2&"'!A1:F4)

This will search in the next tab (cell B2 text name ie: Tab_1 and table from A1 to F4 cells)

MATCH($B2,INDIRECT("'"&$B$2&"'!A1:F4),0)

This will search the exact name (from cell B3 text ie: Table_1) from the tab

So All together you can write below function:

INDEX(INDIRECT("'"&$B$2&"'!A1:F4),MATCH($B3,INDIRECT("'"&$B$2&"'!A1:F4),0),2)

I hope this solution will help you someone who facing for this kind of problems.

英文:

Finally after some research, I found the solution. We can use MATCH function to check the exact row name.

INDIRECT("'"&$B$2&"'!A1:F4)

This will search in the next tab (cell B2 text name ie: Tab_1 and table from A1 to F4 cells)

MATCH($B2,INDIRECT("'"&$B$2&"'!A1:F4),0)

This will search the exact name (from cell B3 text ie: Table_1) from the tab

So All together you can write below function:

INDEX(INDIRECT("'"&$B$2&"'!A1:F4),MATCH($B3,INDIRECT("'"&$B$2&"'!A1:F4),0),2)

I hope this solution will help you someone who facing for this kind of problems.

huangapple
  • 本文由 发表于 2023年2月13日 23:38:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438066.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定