简体   繁体   English

vba excel:对象_global的运行时错误1004方法范围失败

[英]vba excel : runtime error 1004 method range of object _global failed

I'm having the error "runtime error 1004 method range of object _global failed" when I launched the following macro : 启动以下宏时出现错误“对象_global的运行时错误1004方法范围失败”:

Dim nameDebut As Range, nameFin As Range ' <- my global variable
sub mySub()
...
   Set nameDebut = Range("A1").Offset(0, 1)
   Set nameFin = Range("A1").Offset(0, 20)
   Range("nameDebut:nameFin").Select ' <- fail occurs here
...

So I would like to select this range of cells like this. 所以我想选择这样的单元格范围。 Is it possible ? 可能吗 ? Any workaround ? 任何解决方法?

Tx TX

Just change the last line to 只需将最后一行更改为

Range(nameDebut,nameFin).Select 

Not discussing your code, but using select is nearly never needed in VBA. 不讨论您的代码,但是在VBA中几乎不需要使用select Maybe this can help: 也许这可以帮助:

dim myRange as Range
set myRange = Range(nameDebut,nameFin)
' Now use `myRange` for whatever you want to do...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对象&#39;_global&#39;的Excel VBA方法&#39;Range&#39;失败错误1004 - Excel VBA Method 'Range' of object'_global' failed error 1004 VBA运行时错误1004的object_global范围失败 - VBA Runtime error 1004 range of object_global failed VBA运行时错误1004:对象&#39;_global&#39;的方法&#39;Range&#39; - VBA runtime error 1004: Method 'Range' of object'_global' Excel VBA运行时错误1004-“范围类的自动填充方法失败” - Excel VBA Runtime Error 1004 - "Autofill Method of Range Class Failed” 运行时错误&#39;1004&#39;:对象&#39;_global&#39;的方法&#39;range&#39;失败 - runtime error '1004': method 'range' of object '_global' failed Excel VBA 运行时错误'1004'对象'_Global'的方法'范围'失败 - Excel VBA Run-Time Error '1004' Method 'Range' of object'_Global' Failed Excel VBA_ Object 工作表的方法范围失败(运行时错误 1004) - Excel VBA_ Method Range failed for Object Worksheet (Runtime Error 1004) 损坏的Excel VBA宏运行时错误&#39;1004&#39;:对象&#39;_Global&#39;的方法&#39;Range&#39;失败 - Broken Excel VBA Macro Run-time error '1004': Method 'Range' of object '_Global' failed _Global的VBA错误1004对象范围失败 - VBA Error 1004 Object Range failed for _Global VBA运行时错误1004:尝试在Excel 2013中创建表时,对象_Global的方法范围失败 - VBA Run-time error 1004: Method Range of object _Global failed when trying to create tables in Excel 2013
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM