vba 单击按钮后如何返回到单元格 A1?

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

How do I return To Cell A1 after clicking a button?

excelvbaexcel-vba

提问by Mike Barnes

I have a button at the bottom of my excel sheet that generates another sheet ounce clicked. That function works fine but I need to return to the top of the sheet after I click the button and not to the new Sheet.

我的 Excel 工作表底部有一个按钮,单击后会生成另一个工作表盎司。该功能工作正常,但我需要在单击按钮后返回到工作表的顶部,而不是返回到新的工作表。

What kind of VBA code will be used to do this?

将使用哪种 VBA 代码来执行此操作?

回答by matzone

Try this sample ..

试试这个样本..

Application.GoTo ActiveSheet.Range("A1"),True

回答by silkfire

Try this:

尝试这个:

Sheets(1).Select
ActiveSheet.Range("A1").Select

回答by Andrey Gordeev

Use this code:

使用此代码:

MsgBox ThisWorkbook.Sheets("New_sheet_name").Range("A1")

回答by Ripster

Add this to the button click sub. When you click the button this will check what sheet you are currently on, run your code, and when it is done return to the previous sheet with A1 selected in view.

将此添加到按钮单击子。当您单击该按钮时,这将检查您当前在哪个工作表上,运行您的代码,并在完成后返回到上一个工作表并在视图中选择 A1。

Sub Example()
   Dim PrevSheet as Worksheet

   PrevSheet = ActiveSheet

   'Your code that does stuff, creates a new sheet etc..

   PrevSheet.Select
   Range("A1").Select
End Sub