Hey all, looking to reduce the code on my c# if statements as there are several repeating factors and was wondering if a trimmer solution is possible.
I currently have 2 if statements that need to carry out an identical statement, however the only variable is an extra condition on an if statement when a checkbox is not checked. Im just wondering if there is a way to make it one statement or make the condition string variable, heres the compressed version of the code:
if (checkbox.checked) { if (columnname != a && columnname != b && columnname != c) { "statement 1" } } else { if (columnname != a && columnname != b && columnname != c && columnname != A2) { "statement 1" } }
Its like I need to run an if statement within the conditions of an if statement if that makes sense, like this psuedo form:
if (columnname != a && columnname != b && columnname != c && if(checkbox.checked{columnname != A2})
The multiple IF conditions in Excel are IF statements contained within another IF statement. They are used to test multiple conditions simultaneously and return distinct values. The additional IF statements can be included in the “value if true” and “value if false” arguments of a standard IF formula.
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.
It is possible to nest multiple IF functions within one Excel formula. You can nest up to 7 IF functions to create a complex IF THEN ELSE statement. TIP: If you have Excel 2016, try the new IFS function instead of nesting multiple IF functions.
if (columnname != a && columnname != b && columnname != c && (checkbox.checked || columnname != A2)) { "statement 1" }
Should do the trick.
if (columnname != a && columnname != b && columnname != c && (columnname != A2 || checkbox.checked)) { "statement 1" }
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