VBA代码仅在调试模式下工作,并在正常模式下运行时挂起 [英] VBA code works only in the debugging mode and hangs when running in normal mode
问题描述
这个问题让我疯狂。我有以下代码:
This problem is driving me crazy. I have the following code:
'unprotect sheet
If.Range("Start").Row+1<.Range("End").Row then
.Rows(.Range("Start").Row+1 & ":" & .Range("End").Row-1).Select
Selection.Delete Shift:=xlUp
'protect sheet
End if
结束p>当我在调试模式下运行它并跟踪代码,它的工作完美。但是当以正常模式(不调试)运行代码时,它会给我一个错误消息,因为选择Range类失败的方法这个错误发生在以下行中: .Rows(.Range(Start )
任何想法?
请帮助。
when I run it in debugging mode and trace the code, it works perfectly. But when run the code in a normal mode (not debugging) it gives me an error message as " select method of Range class failed" This errors happens in the line: .Rows(.Range("Start").Row +1 ....
that is just after the IF statement.
Any ideas?
Please help.
推荐答案
此错误通常意味着您正在尝试选择属于非活动工作表的范围。
This error usually means you are trying to select a range that belongs to a non-active sheet.
你几乎总是不需要选择任何东西:
You almost always don't need to select anything:
.Rows(.Range("Start").Row+1 & ":" & .Range("End").Row-1).Delete Shift:=xlUp
这篇关于VBA代码仅在调试模式下工作,并在正常模式下运行时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!