vba VBA选择最后一列和最后一行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17928372/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 22:27:50  来源:igfitidea点击:

VBA Select Last Column and Last Row

excelvba

提问by Mark Austin

I am trying to select the bottom most right cell in my field of data. I have a 20x20 grid of data and need to find the last column that it would go down to find the last row that has data. I am having trouble using active cell function with in my second line of code.

我试图在我的数据字段中选择最右下角的单元格。我有一个 20x20 的数据网格,需要找到最后一列,它会向下查找包含数据的最后一行。我在第二行代码中使用活动单元格功能时遇到问题。

 Sub Add

      Range("A2").End(xlToRight).Select
      Range("A2").End(xlDown).Select

 End Sub

回答by LS_???

Sub Add
    ActiveCell.SpecialCells(xlCellTypeLastCell).Select
End Sub

回答by Andy G

If you want to fix your current code:

如果要修复当前代码:

Sub Add
  Range("A2").End(xlToRight).End(xlDown).Select
End Sub

but it will fail (stop short) if there are any blank cells going across or down.

但如果有任何空白单元格穿过或向下,它将失败(停止短暂)。

See the page linked by Head of Catering for better ways to do this.

请参阅餐饮主管链接的页面,了解更好的方法。