如何选择第二行到最后一行的范围 [英] How to select a range of the second row to the last row
问题描述
我目前正在试图弄清楚如何从第二行到最后一行选择一个范围,但更具体地说是在一系列列之间选择一个范围.例如,我想选择Range(A2:L2
)到电子表格中数据的最后一行.
I am currently trying to figure out how to select a range from the second row to the last row, but more specifically between a range of columns. For instance I want to select Range(A2:L2
) to the last row of data in the spreadsheet.
我尝试过
Dim Lastrow As Integer
Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:L2" & Lastrow).Select
但这从A2:L2
一直选择到电子表格的底部.我检查了Lastrow
是否不正确,但是我将其打印到一个单元格中并显示了正确的行数.
But this selects from A2:L2
all the way down to the bottom of the spreadsheet. I have checked to see if Lastrow
was incorrect but I printed it to a cell and the correct count of rows displayed.
推荐答案
尝试一下:
Dim Lastrow As Integer
Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:L" & Lastrow).Select
让我们假装Lastrow
的值为50.当您使用以下命令时:
Let's pretend that the value of Lastrow
is 50. When you use the following:
Range("A2:L2" & Lastrow).Select
然后它正在选择A2到L250的范围.
Then it is selecting a range from A2 to L250.
这篇关于如何选择第二行到最后一行的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!