Search code examples
excelformulasnested-if

Assistance on a Particular Nested IF Excel Formula


Here's a quick summary of what I am trying to do:

I'm trying to set up an Excel workbook that will allow users to paste the results of a SQL query into a RawData worksheet and have multiple other worksheets then grab that data and display it in various formats (graphs, charts, etc.).

This particular formula that I'm trying to write is supposed to look at a certain column in RawData, compare the number listed there to a "key" in the Key worksheet, and then return the text equivalent to the ID displayed in RawData in a new worksheet called StylizedData

For example, if RawData lists 1, then StylizedData will list "Configuration" because 1 is associated with "Configuration" in the Key.

Here is the formula:

=IF(RawData!F60=Key!$C$2,Key!$D$2,
  IF(RawData!F60=Key!$C$3,Key!$D$3,
   IF(RawData!F60=Key!$C$4,Key!$D$4,
    IF(RawData!F60=Key!$C$5,Key!$D$5,
     IF(RawData!F60=Key!$C$6,Key!$D$6,
      IF(RawData!F60=Key!$C$7,Key!$D$7,
       IF(RawData!F60=Key!$C$8,Key!$D$8,
        IF(RawData!F60=Key!$C$9,Key!$D$9,
         IF(RawData!F60=Key!$C$10,Key!$D$10,
          IF(RawData!F60=Key!$C$11,Key!$D$11,
           IF(RawData!F60=Key!$C$12,Key!$D$12,
            IF(RawData!F60=Key!$C$13,Key!$D$13,
             IF(RawData!F60=Key!$C$14,Key!$D$14,
              IF(RawData!F60=Key!$C$15,Key!$D$15,
               IF(RawData!F60=Key!$C$16,Key!$D$16,
                IF(RawData!F60=Key!$C$17,Key!$D$17,
                 IF(RawData!F60=Key!$C$18,Key!$D$18,
                  IF(RawData!F60=Key!$C$19,Key!$D$19,
                   IF(RawData!F60=Key!$C$20,Key!$D$20,
                    IF(RawData!F60="",""))))))))))))))))))))

That whole process is working correctly all the way up until I get to the point where a row in RawData is empty. When the row is empty, it is displaying "No Subcategory", which is the text equivalent of Key!$C$2 and is contained in Key!$D$2. I'm wanting it to display nothing, which I'm trying to accomplish with that last snippet (IF(RawData!F60="","")).

Can anyone help me out here?

Thanks in advance.


Solution

  • =if(iserror(vlookup(RawData!F60,KeyArray,2,0)),"",vlookup(RawData!F60,KeyArray,2,0)

    If the lookup value isn't found the cell gets a "" value. Otherwise it will search for the value contained in F60 in your key array and return the value two cells to the right.

    With Vlookup() your array/range must have the values you are searching for in the first column. Your column/array must also include the column of values you want to return. For instance you would probably use something like $C$2:$D$20 for your key array. It also helps if your key values in your key array are sorted.

    Good luck!