如何选择最后一排 [英] How to select the lastrow
问题描述
我有一个Excel工作表,其中包含如下数据:
I have an excel sheet it contains data as below:
A B C D E F
1 10 11 12 78 45
2 12 15 15 78 45
3 17 18 13 7 45
4 12 45 7 78 78
5 578 54 45 8 78
6 42 72 75 8 78
7 452 22252 2277 87 986
8 752 72 752 878 98638
9 72 72 72 45 78
10 788 72 78 678 465
现在,我想在此excel中选择最后一行.因为每天行号都会改变.
但是我不希望Selection.End(xlToRight).Select
,因为在此excel中,每2列后将出现空白.
例如:
Now, I want to select the last row in this excel. Because everyday the row number will be change.
But I don't want the Selection.End(xlToRight).Select
because in this excel blanks will come after every 2 columns.
Ex:
我想选择A10作为该行的最后一个单元格.
I want to select A10 to last cell in this row.
我创建了"usedrange"方法,但对我来说效果不佳.
I have create "usedrange" method but it doesn’t work well for me.
startcell = Range("B" & Cells.Rows.Count).End(xlUp).Select
endrcell = Range("G" & Cells.Rows.Count).End(xlUp).Select
如何选择要空白的起始行?
How can I select the startrow to endcell with blanks?
请咨询.
推荐答案
要选择包含数据的最后一行,请先从底部向上移动以找到该行,然后在该行上向左移动至找到最后使用的列:
To Select the last row with data, first move upwards from the bottom to find the row and then move leftwards on that row to find that last used column:
Sub SelectLastRow()
Dim nRow As Long, nColumn As Long
nRow = Cells(Rows.Count, "A").End(xlUp).Row
nColumn = Cells(nRow, Columns.Count).End(xlToLeft).Column
Range(Cells(nRow, "A"), Cells(nRow, nColumn)).Select
End Sub
这篇关于如何选择最后一排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!