Instr条件不适用于2个或更多条件

编程入门 行业动态 更新时间:2024-10-13 18:27:41
本文介绍了Instr条件不适用于2个或更多条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Excel VBA中具有以下INSTR条件,不能正常工作(所有时间)

I have the following INSTR condition in Excel VBA which doesn't work (all the time)

STR_TEXT="SKU1234 $100/10' $200/20'" ' < example string IF INSTR(STR_TEXT,"/10'") AND INSTR(STR_TEXT,"/20'") THEN ' code ELSE ' code END IF

对于一些模糊的原因,似乎无法检查这两种情况第一个IF,即使这两个条件匹配,似乎都不起作用,并且进行到ELSE。

For some obscure reason, it seems like it cannot check for both conditions so the first IF, even if both condition match, doesn't seem to work and goes to ELSE.

以下功能正常工作:

STR_TEXT="SKU1234 $100/10' $200/20'" ' < example string IF INSTR(STR_TEXT,"/10'") THEN IF INSTR(STR_TEXT,"/20'") THEN ' code END IF ELSE ' code END IF

正如你所见如果我分开了第一个IF的条件,它是有效的。 但是我希望两个条件都是同一个IF,因为代码是'更干净'。

As you can see, if I separate the conditions on the first IF, it works. But I would prefer to have both conditions in same IF, as code is 'cleaner'.

任何人都知道为什么和/或如何解决它,而不需要将IF放在另一个IF中?

Anyone knows why and/or how to fix it without having to put an IF inside another IF ?

推荐答案

EXMAPLE:

if instr(str_Text,"/10'") > 0 AND instr(str_text,"/20'") > 0 then

Tim说的是,instr函数返回第一个实例的字符串中的位置的字符串被搜索..

What Tim is saying is that the instr function returns the position in the string of the first instance of the string being searched for..

所以在你的例子中:13被返回instr(str_Text,/ 10)。

so in your example: 13 is being returned for instr(str_Text,"/10').

当VBA读取您的版本instr(str_text,/ 10;)(没有> 0)时,它会看到结果不是1(这意味着true),所以它总是命中其他)

更多推荐

Instr条件不适用于2个或更多条件

本文发布于:2023-10-26 17:41:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530870.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条件   不适用于   更多   Instr

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!