vba VBA使用单元格引用激活单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13457909/
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
VBA activating a cell with a cell reference
提问by harryg
So I have a very simple line of code that should activate a cell on another sheet but in the same workbook but I can't figure out why it doesn't work:
所以我有一行非常简单的代码,它应该激活另一个工作表上但在同一个工作簿中的单元格,但我不知道为什么它不起作用:
Sheets("me").Range(Cells(rownum, colnum)).Activate
It give an "application or object defined" error. rownum
and colnum
are defined variables and when hovering them in debug mode they show integer values.
它给出了“应用程序或对象定义”错误。rownum
和colnum
是定义的变量,在调试模式下将它们悬停时,它们显示整数值。
回答by Jook
You need to activate the worksheet before you activate a cell on it.
您需要先激活工作表,然后再激活其上的单元格。
Try this instead:
试试这个:
Public Sub test()
With Sheets("me")
.Activate
.Cells(rownum, colnum).Activate
End With
End Sub
回答by Patrick Honorez
From Excel 2003 help:
Activates a single cell, which must be inside the current selection. To select a range of cells, use the Select method.
来自 Excel 2003 帮助:
激活单个单元格,该单元格必须在当前选择范围内。要选择一系列单元格,请使用 Select 方法。
By the way, do you REALLY need to activate or select that range ? In 90% of the code I see, those .Select
are totally unnecessary !
顺便说一句,您真的需要激活或选择该范围吗?在我看到的 90% 的代码中,这些.Select
都是完全没有必要的!