使用 VBA 滚动到 Excel 中的最后一行文本

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

Scroll to the last row of text in Excel using VBA

excelvbaexcel-vbaspreadsheet

提问by Michaelb88

Would someone be able to tell me how I can make my spread sheet move the last row of text from VBA.

有人能告诉我如何让我的电子表格移动 VBA 中的最后一行文本。

Currently I use the following code:

目前我使用以下代码:

Range("p65536").End(xlUp).Select

This works, but it also moves to a particular column. I would like to do this but keep the current columns on the screen.

这有效,但它也会移动到特定列。我想这样做,但将当前列保留在屏幕上。

回答by Peter Albert

Try this code:

试试这个代码:

ActiveSheet.Cells(ActiveSheet.Rows.Count, Selection.Column).End(xlUp).Select

ActiveSheet.Cells(ActiveSheet.Rows.Count, Selection.Column).End(xlUp).Select

回答by ChrisB

What you want to change is ScrollRow. If you also wanted to scroll horizontally you would set ScrollColumn.

你想要改变的是ScrollRow. 如果您还想水平滚动,您可以设置ScrollColumn.

Dim targetSheet As Worksheet
Set targetSheet = ActiveSheet   ' Refer to your sheet instead of ActiveSheet.

targetSheet.Activate    ' Make sure the worksheet is active to prevent errors.

With targetSheet.Cells(targetSheet.Rows.Count, Selection.Column).End(xlUp)
    .Select ' not required to change the focus/view
    ActiveWindow.ScrollRow = .Row
End With