返回值 相对单元格引用 Excel VBA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15554853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Return Value Relative Cell Reference Excel VBA
提问by user1902860
I need to return the value of a cell, one row down and over to the last column in the table without making that cell active. I already have VBA returning the last column.
This does not work.
我需要返回一个单元格的值,向下一行返回到表格中的最后一列,而不会使该单元格处于活动状态。我已经让 VBA 返回最后一列。
这不起作用。
WorkPercent = Cells(2, LastCol - 1).Value
回答by Geoff
Assuming you're talking about "the cell one row below and one column to the right of a specific table", you could try:
假设您正在谈论“特定表格下方一行和一列右侧的单元格”,您可以尝试:
Sub main()
Dim sheet As Worksheet
Dim tbl As ListObject
Dim lastCol As Integer
Dim lastRow As Integer
Set sheet = ActiveSheet
Set tbl = sheet.ListObjects("tbl")
lastCol = tbl.DataBodyRange.Columns(tbl.DataBodyRange.Columns.Count).Column
lastRow = tbl.DataBodyRange.Rows(tbl.DataBodyRange.Rows.Count).Row
MsgBox sheet.Cells(lastRow + 1, lastCol + 1)
End Sub
回答by Geoff
Kindly use the Offset property
请使用 Offset 属性
WorkPercent = Cells(2, LastCol - 1).Offset(1, 0).Value