在excel vba中的特定工作表中选择范围 [英] Select range in a particular sheet in excel vba
问题描述
我有一个关于使用excel vba在特定工作表中选择范围的问题。
我不知道为什么以下内容不起作用:
工作簿(N& A)范围(B4:F16)选择
但是这样做:
Thisworkbook.Sheets(N& A)。激活
ActiveSheet.Range B4:F16)选择
VBA代码编程在N& A / p>
有谁可以让我知道是什么原因?
谢谢!
你基本上回答了你自己的问题。以下是 Excel 2003帮助:
如果您使用Select方法选择单元格,请注意,Select仅在活动工作表上工作,如果从模块运行Sub过程,则选择方法将失败,除非您的过程在使用单元格范围之前的Select方法时激活工作表。
更重要的是,请记住,很少需要使用在VBA中选择
,它应该是如果可能。
I have a question about selecting a range in a particular sheet using excel vba.
I don't know why the following is not working:
Thisworkbook.Sheets("N&A").Range("B4:F16").select
However this works:
Thisworkbook.Sheets("N&A").Activate
ActiveSheet.Range("B4:F16").Select
The VBA code is programmed on "N&A" sheet.
Could anyone let me know what could be the reason?
Thank you!
You've basically answered your own question. Here's an excerpt from Excel 2003 help:
"If you use the Select method to select cells, be aware that Select works only on the active worksheet. If you run your Sub procedure from the module, the Select method will fail unless your procedure activates the worksheet before using the Select method on a range of cells."
More importantly, remember that it's rarely necessary to use Select
in VBA, and it should be avoided if possible.
这篇关于在excel vba中的特定工作表中选择范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!