单张/范围选择(组合)不工作 [英] Sheet / Range Select (combined) not working

查看:96
本文介绍了单张/范围选择(组合)不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的VBA中有些事情发生了变化,我不能让我完成某些例程。我在下面列出了一个非常简单的例子。如果有人经历过这个问题,我将非常感谢任何解决这个问题的支持。




  • 问题简单的例子:



当我使用以下代码,它可以正常工作。

 范围(B3)选择

当我结合它们时,我得到一个1004错误

 表格(Sheet1)。范围(B3)选择

我查看了参考/文档库,在这里没有任何改变。它必须是简单的,但我只是不能把我的手指。

解决方案

如果你绝对必须在单行代码中执行此操作,然后交换Select for a Application.GoTo ,它接受工作表和单元格范围。

  application.goto range(Sheet1!B3)

然而,几乎从来没有必要(最常见的是反效果)使用 Range。选择方法来引用要处理的单元格或单元格。请参阅如何避免在Excel VBA宏中使用选择以避免依赖选择和激活来实现您的目标。


Something has changed in my VBA that is not allowing me to complete certain routines. I have listed a very simple example below. If anyone has experienced this I would be really appreciate any support in resolving this issue.

  • Simple example of issue:

When I use the following code it works fine.

Sheets("Sheet1").Select
Range("B3").Select

When I combine them I get a "1004" error

Sheets("Sheet1").Range("B3").Select

I checked the reference/document library and nothing appears to have changed in here. It has to be something simple but I just can't put my finger on it.

解决方案

If you absolutely must do it in a single line of code then swap the Select for an Application.GoTo which accepts both worksheet and cell range.

application.goto range("Sheet1!B3")

However, it is almost never necessary (and most often counter-productive) to use the Range .Select method to reference a cell or cells to work on. See How to avoid using Select in Excel VBA macros for methods on getting away from relying on select and activate to accomplish your goals.

这篇关于单张/范围选择(组合)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆