vba Excel 运行时错误 16 表达式太复杂
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13551986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel Run-time error 16 expression too complex
提问by JaamShikan
I have this basic code in an Excel sheet
我在 Excel 工作表中有这个基本代码
For x = 1 To ThisWorkbook.Worksheets("GRP0").Range("D9:D112").Rows.Count
' do work here
Next x
though when I execute it gives the error
虽然当我执行它时会出现错误
Run-time error '16':
Expression too complex
I'm using Excel 2007 in compatibility mode, the sheet, I believe was made for/in Excel 2003, if that helps. Any ideas as to what is causing the error?
我在兼容模式下使用 Excel 2007,如果有帮助,我相信该工作表是为/在 Excel 2003 中制作的。关于导致错误的原因有什么想法吗?
采纳答案by Kazimierz Jawor
Let me just answer this question and let it leave 'unanswered' section... and for others who would look for the answer and see perfectly written question.
让我回答这个问题,让它留下“未回答”的部分……以及其他想要寻找答案并看到写得很完美的问题的人。
Problem described happens from time to time. I don't know exact reason but there is one simple way to solve it. You just need to use variable, set its value before loop starts and use this variable in loop starting line. This could be as follow:
描述的问题不时发生。我不知道确切的原因,但有一种简单的方法可以解决它。您只需要使用变量,在循环开始之前设置其值并在循环开始行中使用此变量。这可能如下:
Dim rowsCount As Long
rowsCount = ThisWorkbook.Worksheets("GRP0").Range("D9:D112").Rows.Count
'and any other complex statement could be placed here
For x = 1 To rowsCount
'do work here
Next x
According to my experience all 'expression too complex' problems could be solved that way.
根据我的经验,所有“表达太复杂”的问题都可以通过这种方式解决。