通过VBA选择Range类的方法失败 [英] Select method of Range class failed via VBA

查看:1216
本文介绍了通过VBA选择Range类的方法失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在使用的代码,而且我遇到这个问题。我是Excel的新手,我无法弄清楚是什么问题。

This is the code that I'm currently working with, and I'm getting this problem. I'm novice at Excel and I can't figure out what's wrong.

Private Sub cmdRecord_Click()
Sheets("BxWsn Simulation").Range("Result").Select //This is the line with the problem, as excel told me.
    Selection.Copy
    Sheets("Reslt Record").Select
    Sheets("Reslt Record").Range("A5000").End(xlUp).Offset(1).Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("CuCon Simulator").Select
    Application.CutCopyMode = False
    Range("Improvement").Select
End Sub

错误是通过VBA选择Range类失败的方法,错误1004.
任何想法?

The error is Select method of Range class failed via VBA, Error 1004. Any ideas?

谢谢。

编辑:

所以我只是将代码更改为

So I just changed the code to

Sheets("BxWsn Simulation").Select
Range("Result").Select

我相信这是你的意思,使其活跃?
但是我仍然得到对象_Worksheet失败的Method'Range',错误1004

I believe this is what you mean by making it active? However I'm still getting Method 'Range' of object '_Worksheet' failed, error 1004

推荐答案

我相信你有同样的问题在这里。

该表必须是活动的,然后才能选择一个范围。

I believe you are having the same problem here.
The sheet must be active before you can select a range on it.

另外,don不要使用工作表名称限定符:

Also, don't omit the sheet name qualifier:

Sheets("BxWsn Simulation").Select
Sheets("BxWsn Simulation").Range("Result").Select

或者,

With Sheets("BxWsn Simulation")
  .Select
  .Range("Result").Select
End WIth

这是一样的。

这篇关于通过VBA选择Range类的方法失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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