简体   繁体   English

为什么我的 excel vba if/or 语句不能正常工作?

[英]Why doesn't my excel vba if/or statement work correctly?

I'm comparing values of numbers from 2 data sheets, and I've dropped the relevant data from both into their own arrays.我正在比较 2 个数据表中的数字值,并且我已将两者的相关数据放入它们自己的 arrays 中。 I need to find matching values to run other steps of analysis.我需要找到匹配的值来运行其他分析步骤。

    For i = Lbound(Array1) to UBound(Array1)
        For j = LBound(Array2) to UBound(Array2)
            If (criteria for Array2) then
               variable = 11111
            Else
               variable = 22222
            End if
            If variable = Array1(i,1) Or variable = Array1(i,2) or variable = Array1(i,3) then
               more steps
            Else
               more steps
            End if
         next j
    next i

The first if statement sets the variable correctly, but the variable doesn't match any of the criteria.第一个 if 语句正确设置变量,但变量不匹配任何条件。 It doesn't go to the else like it should.它不像其他人那样 go 。 Now I only know this because I walked through the code step by step.现在我只知道这一点,因为我一步一步地浏览了代码。 If I just F5 and run the thing, "Excel is not responding".如果我只是 F5 并运行它,“Excel 没有响应”。 I don't know what the hang up it.不知道挂了怎么办All of my variables are declared and assigned a type, I'm not missing any closing statements.我所有的变量都被声明并分配了一个类型,我没有错过任何结束语句。 And I have no idea what I'm doing wrong.而且我不知道我做错了什么。

What do I need to check for in my code?我需要在我的代码中检查什么?

EDIT编辑

Sorry, but in this instance I'm not allowed to upload any code here.抱歉,但在这种情况下,我不允许在这里上传任何代码。 It's work related, NDA kind of stuff.这是工作相关的,NDA 之类的东西。 Hence the pseudo code.因此,伪代码。 What I need to show wouldn't be a big deal(at least I don't think it would), but I'm not risking it.我需要展示的东西没什么大不了的(至少我认为不会),但我不会冒险。

My apologies.我很抱歉。

The solution, as it turns out, has to do with a poorly named array(not me) and a simple typo(definitely me).事实证明,解决方案与命名不佳的数组(不是我)和一个简单的错字(肯定是我)有关。 I'm certain that would have been an easy solve for the good citizens of Stack Overflow if I would have been allowed to post actual code.我敢肯定,如果允许我发布实际代码,那么对于 Stack Overflow 的好公民来说,这将是一个简单的解决方案。

For what's it worth, I think it's dumb that I couldn't in this case.对于它的价值,我认为在这种情况下我不能这样做是愚蠢的。 Thanks @ScottCraner and @SuperSymmertry for trying to be helpful even without much to go on.感谢@ScottCraner 和@SuperSymmertry,即使对 go 没有太多帮助,也能提供帮助。

Super, I'm still curious about Val.超级,我还是对瓦尔很好奇。 If you've got a minute, I would appreciate more knowledge on that.如果您有时间,我将不胜感激有关这方面的更多知识。 Anything from an actual person is better than Microsoft documentation.任何来自真实人物的东西都比 Microsoft 文档要好。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM