.Cells(.Rows.Count,“A”)的含义。End(xlUp).row [英] Meaning of .Cells(.Rows.Count,"A").End(xlUp).row
问题描述
我只是想知道你是否可以帮助我更好地了解什么 .Cells(.Rows.Count,A)。End(xlUp).row
。我理解 .End
部分之前的部分。
I was just wondering if you could help me better understand what .Cells(.Rows.Count,"A").End(xlUp).row
does. I understand the portion before the .End
part.
推荐答案
用于查找包含列A中的数据的工作表中包含数据的行数。完整的使用是
It is used to find the how many rows contain data in a worksheet that contains data in the column "A". The full usage is
lastRowIndex = ws.Cells(ws.Rows.Count, "A").End(xlUp).row
其中 ws
是一个Worksheet对象。在问题示例中,暗示该声明位于中
块
Where ws
is a Worksheet object. In the questions example it was implied that the statement was inside a With
block
With ws
lastRowIndex = .Cells(.Rows.Count, "A").End(xlUp).row
End With
-
ws.Rows.Count
返回工作表中的总计数(1048576在Excel 2010中) -
.Cells(.Rows.Count,A)
返回列 在工作表中
ws.Rows.Count
returns the total count of rows in the worksheet (1048576 in Excel 2010)..Cells(.Rows.Count, "A")
returns the bottom most cell in column "A" in the worksheet
然后是 End
方法。 文档对于
返回一个Range对象,表示包含源范围
Returns a Range object that represents the cell at the end of the region that contains the source range
特别是它没有定义什么是区域。我的理解是一个区域是非空单元格的连续范围。因此,预期的用途是从区域中的单元开始,并从原始单元格中以该方向找到该区域中的最后一个单元格。但是,当您不使用它时,有多种例外:
Particularly it doesn't define what a "region" is. My understanding is a region is a contiguous range of non-empty cells. So the expected usage is to start from a cell in a region and find the last cell in that region in that direction from the original cell. However there are multiple exceptions for when you don't use it like that:
- 如果范围是多个单元格,它将使用该区域的
rng.cells(1,1)
。 - 如果范围不在区域中,或范围已经在区域的末尾,则它将沿着该方向行进,直到它进入区域并返回遇到的第一个细胞在该地区。
- 如果遇到工作表的边缘,它将返回该工作表边缘的单元格。
- If the range is multiple cells, it will use the region of
rng.cells(1,1)
. - If the range isn't in a region, or the range is already at the end of the region, then it will travel along the direction until it enters a region and return the first encountered cell in that region.
- If it encounters the edge of the worksheet it will return the cell on the edge of that worksheet.
所以 Range.End
不是一个简单的功能。
So Range.End
is not a trivial function.
-
.row
返回该单元格的行索引。
.row
returns the row index of that cell.
这篇关于.Cells(.Rows.Count,“A”)的含义。End(xlUp).row的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!