vba 选择工作表时转到特定单元格

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

go to specific cell when a worksheet is selected

excel-vbavbaexcel

提问by Mansour

I want to go to specific cell when a worksheet is selected

我想在选择工作表时转到特定单元格

Private Sub Worksheet_Cellselection()
ActiveSheet Goto:="D5"
End Sub

That one does not work

那个不行

回答by Shai Rado

You need to use the Worksheet_Activateevent of the relevant worksheet:

您需要使用Worksheet_Activate相关工作表的事件:

Private Sub Worksheet_Activate()

Range("D5").Select

End Sub

To use for several worksheets in a Workbook, move the code to Workbook_SheetActivateevenrt (inside the Workbooklevel):

要用于工作簿中的多个工作表,请将代码移动到Workbook_SheetActivateeventrt(在Workbook关卡内):

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

Select Case Sh.Name
    Case "Sheet1", "Sheet2", "Sheet4" '<-- run it only for sheet's with these names
        Range("D5").Select
End Select

End Sub

回答by Diego Ribba

Application.Goto ActiveSheet.Range("D5")