vba 在电子表格左上角显示选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1160195/
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
Display selection at upper left corner of spreadsheet
提问by
hi is it possible to do this kind of things in excel-2007 vb...
嗨,可以在 excel-2007 vb 中做这种事情吗?
for example user selects cell or range.... let's say cell G13, now this cell will be displayed on the upper-left corner of the sheet (i.e. where usually A1 resides by default) in the case of range selection the upper-left corner of the range will be displayed in upper-left corner of the worksheet...
例如用户选择单元格或范围......假设单元格G13,现在这个单元格将显示在工作表的左上角(即默认情况下通常A1所在的位置)在范围选择左上角的情况下范围的一角将显示在工作表的左上角...
thanks a lot in advance!
非常感谢!
采纳答案by Lance Roberts
Here is how you get the spreadsheet to roll to the cell you want:
以下是让电子表格滚动到所需单元格的方法:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
ActiveWindow.ScrollColumn = Target.Column
ActiveWindow.ScrollRow = Target.Row
Application.EnableEvents = True
End Sub
I think you will find that this will drive the users crazy, but you can probably modify it to get a friendlier effect.
我想你会发现这会让用户发疯,但你可以修改它以获得更友好的效果。
回答by shahkalpesh
ALT + F11
Double click on ThisWorkbook in the treeview on left (inside VBA).
Paste this code into WorkBook class
ALT + F11
在左侧的树视图中双击 ThisWorkbook(在 VBA 中)。
将此代码粘贴到 WorkBook 类中
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Cells(1, 1).Value = Selection.Cells(1).Address
End Sub
Change Selection.Cells(1).Address
to Selection.Cells(1).Value
更改Selection.Cells(1).Address
为Selection.Cells(1).Value
Note: This will occurr for all sheets inside the workbook. You could change it make it work for a specific sheet by adding a check using the Sh
instance in the code.
注意:对于工作簿中的所有工作表都会发生这种情况。您可以通过使用Sh
代码中的实例添加检查来更改它使其适用于特定工作表。