指向 Excel 中相对的其他工作表

发布于 2024-09-29 23:49:43 字数 194 浏览 8 评论 0原文

我正在尝试找到一种方法,从单元格中获取位于当前工作表左侧(托盘下方)的工作表中的单元格的数据。

我知道如何通过以下方式调用其他工作表

=Sheet1!A1

但现在我需要最好的解释有

=Sheet[-1]!A1

任何想法吗?

I'm trying to find a way to from a Cell get the data from a cell in the Sheet that lies to the Left (down in the tray) of the current Sheet.

I know how to call to other sheets via

=Sheet1!A1

But now I need something best explained with

=Sheet[-1]!A1

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦一生花开无言 2024-10-06 23:49:43

使用 Tab 键顺序作为计算的基本部分是 Excel 计算的一种复杂且危险的方法。 Excel 提供了许多替代方案,您最好使用它们:

  1. 贝利撒留建议的简化版本是:=INDIRECT(A1 & "!A2") 其中单元格 A1 包含您的姓名数据源表和 A2 具有数据源表中目标单元格的名称。如果您知道感兴趣的工作表的名称(或可以通过某种方式查找),请使用此方法。

  2. 如果您需要经常执行此操作,您可能希望将数据导出到实际数据库(即 MS Access)中。然后您可以进行标准 SQL 查询并将结果导入到 Excel 文件中。

  3. 如果您绝对想走 VBA 路线,那么您必须编写一些代码:
    3a.获取活动工作簿的所有名称并将它们存储在数组中。
    3b.标识该数组中当前活动工作簿的索引号。从该索引中减去 1 以使工作表位于左侧。
    3c.从该工作表中获取单元格值。

  4. 您还可以对命名范围感到奇怪。在 Excel 2003 中,转到插入->名称->定义,添加新的命名范围,您可以在计算中使用该名称,而不是按行和列引用单元格。

编辑

这个的整个想法是
您已经安排好了表格,并且
能够移动它们,并且
应更改计算。 – 格纳特
1小时前

拜托,拜托,不要这样做。对于初学者来说,这不是与电子表格交互的标准方法。您的最终用户可能会感到困惑,甚至可能不会要求澄清。

您将想要探索数据验证的想法:

  1. 使用数据->验证,创建一个下拉菜单,列出工作簿中的所有工作表(如果名称所有工作表都是静态的,您可以对它们进行硬编码,否则,您将需要一些 VBA 来拉动它们)。
  2. 然后用户只需选择他们选择的工作表,indirect() 将自动更新所有内容。

或者,您也可以查看工具->场景。我不知道有谁使用此功能,但您可能是一个很好的人选。基本上,它可以让您查看使用不同数据集(即“场景”)的计算结果,以便用户可以在它们之间来回切换。

使用上述两种方法中的任何一种,您很有可能完全避免使用 VBA,从而避免用户在打开文件时看到烦人的警告消息。

Using the tab order as a fundamental part of your calculations is a complicated and risky approach to Excel calculations. Excel offers many alternatives which you'd be better off using:

  1. A simplified version of belisarius's suggestion is: =INDIRECT(A1 & "!A2") where cell A1 has the name of your datasource sheet and A2 has the name of your target cell in your datasource sheet. If you know the name of your sheet of interest (or can look it up in some way), use this method.

  2. If you need to do this often, you might want to export the data into an actual database (i.e. MS Access). Then you can make standard SQL queries and import the results into your Excel file.

  3. If you absolutely want to go the VBA route, then you'd have to write some code that:
    3a. Grabs all the names of the active workbook and stores them in an array.
    3b. Identifies the index number of the currently active workbook in that array. Subtract 1 from that index to get the sheet to the left.
    3c. Gets the cell value from that sheet.

  4. You can also get freaky with Named Ranges. In Excel 2003, go to Insert->Name->Define, add a new Named Range and you can use that name in your calculations instead of referring to the cell by row and column.

Edit

The whole Idea with this one, is that
you have the Sheets arranged, and are
able to move them around, and that
shall change the calculations. – Gnutt
1 hour ago

Please, please, don't do that. For starters, this isn't a standard method of interaction with a spreadsheet. Your end-users will likely be confused and may not even ask for clarification.

You'll want to explore the idea of data validation:

  1. Using Data->Validation, make a drop-down menu listing all the sheets in the workbook (if the names of all the sheets are static, you can just hardcode them, otherwise, you'll need some VBA to pull them).
  2. Then the user just picks the sheet of their choice and indirect() will automatically update everything.

Alternatively, you can also check out Tools->Scenarios. I don't know anybody who uses this feature, but you might be a good candidate for it. Basically, it lets you see the results of calculations using different datasets (i.e. "scenarios") so the user can go back and forth between them.

Using either of the 2 methods above, there's a good chance you can avoid VBA entirely, thus saving users that annoying warning message when they open your file.

假面具 2024-10-06 23:49:43
=INDIRECT("Sheet"&TEXT(VALUE(MID(CELL("filename",A8),FIND("]",CELL("filename",A8))+1,256))-1,"#")&"!A1")  

注意事项:

  1. 您的工作簿必须事先保存,
  2. A8 可能会替换为对任何非错误单元格的引用
=INDIRECT("Sheet"&TEXT(VALUE(MID(CELL("filename",A8),FIND("]",CELL("filename",A8))+1,256))-1,"#")&"!A1")  

Caveats:

  1. Your workbook must be saved previously
  2. A8 may be replaced by a reference to ANY non-error cell
昔梦 2024-10-06 23:49:43

我知道这在这里不被视为好的做法,但我想做类似的事情。它确实在一定程度上复制了数据库功能,但当某些东西已经到位时,我没有时间或支持从头开始构建数据库功能。

我希望能够执行此操作的原因是创建一个链接到工作簿中所有工作表的汇总表,并在插入新工作表时自动扩展。这是为了管理一个大型销售/报告电子表格,其中包含许多不同的业务部门,这些部门都具有相同的结构(即使用相同的工作表格式为不同的人报告相同的结果。人员流动率很高。我想要几个总结如果每次都重新创建所有表,那么管理起来会非常耗时。

应该能够使用 row() 作为索引标记来定义信息。您想要使用 REPLACE、OFFSET 或 INDEX 之类的内容,但不能,因为它们仅引用 2D 数组,

而 Excel 将 3D 引用视为统计函数的数组,但您可能不会这样做。有 SUM(sheetX:sheetY!A1) 并能够在其间添加一个工作表,但没有(例如) INDEX(sheetX:sheetY!A1,n) 函数我尝试使用这些 2D 函数作为 的一部分。数组公式,并将 3D 参考定义为数组或命名范围...值得一试:)。

所以我相信这是一个有效的行动。我也相信一定有一种方法可以做到这一点,但现在我依靠 UDF,它存在因计算问题或操作 Workbook_SheetChange 函数或类似函数而导致错误的风险。或者创建一个主表来控制通过使用基于所有工作簿数组的子例程填充的所有其他表。

I know it's not seen here as good practice, but I want to do something similar. And it does replicate database functionality to an extent but I don't have the time or support to build one from scratch when there's something already half in place.

The reason I want to be able to do this is to create a summary table that links to all the worksheets in the workbook, and automatically extends if you insert a new worksheet. This is to manage a large sales / reporting spreadsheet with lots of different business units that all have the same structure (ie use the same worksheet format to report the same outcomes for different people. There is a high turnover. I want to have several summary sheets reporting different aspects of the source sheets. This is very time consuming to manage if recreating all of the tables each time.

You should be able to use the row() as an index marker to define the information that you want using something like REPLACE, OFFSET or INDEX but you can't as they only refer to 2D arrays.

Whereas Excel treats 3-D references as arrays for statistical functions it does not seem to do the same for reference functions. You might have SUM(sheetX:sheetY!A1) and be able to add a sheet in between, there is not (eg) a INDEX(sheetX:sheetY!A1,n) function. I've tried experimenting using these 2D functions as part of array formulas, and defining the 3D reference as an array or a named range... well it was worth a go :).

So I believe it's a valid action. I also believe there must be a way to do it, but for now I'm falling back on a UDF that has the risk of errors caused by calculation issues, or manipulating a Workbook_SheetChange function or similar. Or creating a single master sheet to control all the others which is populated by using a subroutine based on an array of all workbooks.

娜些时光,永不杰束 2024-10-06 23:49:43

这些功能对我来说效果很好。他们获得工作表索引(父级
您调用它们的范围),从该索引中添加或减去,然后创建
该(相对)工作表的范围和传入的地址。

Function relativeSheet(r As Range, iRelative As Integer)
   Application.Volatile
   relativeSheet = Sheets(r.Cells(1, 1).Parent.Index + iRelative).Range(r.Address)
End Function

Function prevSheet(r As Range)
    prevSheet = relativeSheet(r, -1)
End Function

Function nextSheet(r As Range)
    nextSheet = relativeSheet(r, 1)
End Function

these functions work well for me. They get the worksheet index (the parent of
the range you call them with), add or subtract from that index, and then create
a range from that (relative) sheet and the address passed in.

Function relativeSheet(r As Range, iRelative As Integer)
   Application.Volatile
   relativeSheet = Sheets(r.Cells(1, 1).Parent.Index + iRelative).Range(r.Address)
End Function

Function prevSheet(r As Range)
    prevSheet = relativeSheet(r, -1)
End Function

Function nextSheet(r As Range)
    nextSheet = relativeSheet(r, 1)
End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文