Search code examples
stringexcelif-statementexcel-formulaworksheet-function

Nested formulas with error handling


I have data and would like to use formulas to determine if the installed version is x86 or x64:

OSTYPE                                          SHORTPATH                                       VERSION     VERSIOND
Microsoft Windows 7 Enterprise Edition, 64-bit  C:\PROGRAM FILES (X86)\JAVA\JRE1.8.0_45\BIN\    8.0.45.14   8.0.45.14 x86
Microsoft Windows 7 Enterprise Edition, 64-bit  C:\PROGRAM FILES\JAVA\JRE1.8.0_66\BIN\          8.0.660.18  8.0.660.18 x64
Microsoft Windows 7 Enterprise Edition, 32-bit  C:\PROGRAM FILES\JAVA\JRE6\BIN\                 6.0.510.9   6.0.510.9 x86

The intent is that VERSIOND will contain the VERSION value and then append either x86 for a 32bit install or x64 for 64bit install.

If SHORTPATH contains "(x86)" then it's a 32bit install
If SHORTPATH doesn't contain "(x86)" and OSTYPE contains "64-bit" then it's a 64bit install
If SHORTPATH doesn't contain "(x86)" and OSTYPE contains "32-bit" then it's a 32bit install

I've almost got it working via:

=IF(ISERROR(SEARCH("(x86)";D2));IF(SEARCH("64-bit";C2)>0;CONCATENATE(E2;" x64");CONCATENATE(E2;" x86"));CONCATENATE(E2;" x86"))

Column C is OSTYPE, column D is SHORTPATH and column E is VERSION.

It works except when OSTYPE is 32-bit, and it's because of SEARCH("64-bit";C2)>0 returning #VALUE!'

How to add the second ISERROR for handling that error?


Solution

  • A shorter version:

    =E2&" "&IF(AND(ISERROR(SEARCH("x86";D2));NOT(ISERROR(SEARCH("64-bit";C2))));"x64";"x86")