I'm trying to do two conditions on a single If statement in vbscript. Should be really simple, but it's not working. Something like:
If Not (fileName = testFileName) & (fileName <> "") Then Else ....
I'm making it two if statements to get it working, but can I do a not conditional with an "and" with another not condition?
If you have to write an IF statement with 3 outcomes, then you only need to use one nested IF function. The first IF statement will handle the first outcome, while the second one will return the second and the third possible outcomes. Note: If you have Office 365 installed, then you can also use the new IFS function.
Answer:To write your IF formula, you need to nest multiple IF functions together in combination with the AND function. As one final component of your formula, you need to decide what to do when none of the conditions are met.
While Excel will allow you to nest up to 64 different IF functions, it's not at all advisable to do so.
Use the 'And' keyword for a logical and. Like this:
If Not ((filename = testFileName) And (fileName <> "")) Then
As Hogan notes above, use an AND
instead of &
. See this tutorial for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With