首页 > 解决方案 > 从第一行中选定行的第二行字段中获取值

问题描述

I am looking to obtain the corresponding value from the 1st-row field in a pivot table when a value in the 2nd-row field is selected.

我有一个两行数据透视表,第一行是工作表名称,第二行是单元格引用。

数据透视表示例

我计划使用这些信息来创建超链接操作。What I am struggling to get however is the corresponding sheet name from row1 when a cell reference in row2 is selected.

在上面的示例表中,我可以在选中单元格引用(例如 A$3$)时捕获它,但我不知道如何获取工作表数据(在此示例中为 Sheet3)

标签: excelvbapivot-table

解决方案


也许不是最好的答案,但对我来说,足够优雅:

IIf(IsEmpty(Target.Offset(0, -1)), Target.Offset(0, -1).End(xlUp).Value, Target.Offset(0, -1).Value)

这将检查上一列中的单元格是否有值,如果有则返回,否则将返回其正上方的第一个非空单元格中的值。


推荐阅读