[英]Fetch value from another sheet where the cell reference changes
I wish to grab the value from another sheet where the cell reference will change, it changes because im using the lastrow function to enter a autosum into the last row as the data will always change from day to day.我希望从另一个单元格引用将更改的工作表中获取值,它会更改,因为我使用 lastrow function 将自动和输入到最后一行,因为数据总是每天都在变化。
I'm stuck on how i can reference the cell required from another sheet.我被困在如何从另一张纸上引用所需的单元格。
This is the code which creates the auto sum in my sheet named "A" and i want to display the result of this autosum in another sheet.这是在名为“A”的工作表中创建自动求和的代码,我想在另一张工作表中显示此自动求和的结果。
Dim lastrow1 As Long
lastrow1 = ActiveSheet.Cells(Rows.Count, "J").End(xlUp).Row + 1
ActiveSheet.Cells(lastrow1, "J").Value = "=Sum(J2:J" & lastrow1 - 1 & ")"
You can do this without VBA.您可以在没有 VBA 的情况下执行此操作。 I don't know what your data looks like, so let's say this is your data:我不知道您的数据是什么样的,所以假设这是您的数据:
My personal preference is to put column sums at the top of the column, that way you can freeze the header and sum rows and have the ability to scroll through the data while still seeing the sums.我个人的偏好是将列总和放在列的顶部,这样您就可以冻结 header 和行总和,并且能够在查看总和的同时滚动数据。 To do that, put the headers in Row 2 and start the data in Row 3. Then Row 1 would be C1=SUM(C3:C1000)
.为此,将标题放在第 2 行并在第 3 行开始数据。然后第 1 行将是C1=SUM(C3:C1000)
。 Then you can easily reference C1 in another sheet without VBA.然后,您可以在没有 VBA 的情况下轻松地在另一张表中引用 C1。
Alternatively, you could format your data as a table.或者,您可以将数据格式化为表格。 In the Table Design section of the ribbon, mark "Total Row" to create a row at the bottom that sums up all the data above.在功能区的表设计部分中,标记“总行”以在底部创建一行,汇总上述所有数据。 With this way, you could reference the cell with the sum by calling VLOOKUP like this: VLOOKUP("Total",Table1[#All],3,FALSE)
通过这种方式,您可以通过调用 VLOOKUP 来引用带有总和的单元格,如下所示: VLOOKUP("Total",Table1[#All],3,FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.