Multiple nested IF STATEMENTS with NESTED VLOOKUP or INDEX?MATCH with LEFT in each nest

rspradley

New Member
Joined
Feb 3, 2019
Messages
3
Hello. Im a bit new to the INDEX and MATCH method and I'm really not sure if thats the best way, or if VLOOKUOP is better, or something else entirely.

I have a workbook with several sheets, the first is "invoice form", this is where the formula is located.
The rest of the sheets coincide with a different categories. These sheets start with 3 numbers such as "101 - PPE", "102 - Soil", and "103 - Oven".

I have the following example:

This is the "Invoice Form" Sheet
Part #Description
101-PART1Formula will go here
102-PART2Formula will go here
103-PART3Formula will go here
104-PART4Formula will go here

<tbody>
</tbody>








This is the "101 - PPE" Sheet
Part NumberPart Description
101-PART1Leather Glove
101-PART2Hard Hat
101-PART3Safety Vest

<tbody>
</tbody>







This is the "102 - Soil" Sheet
Part NumberPart Description
102-PART1Soil Mold
102-PART2Soil Brush
102-PART3Soil Tray

<tbody>
</tbody>







I need the formula to automatically look at the part number in cell A2 on "Invoice Form" and then determine the first 3 digits (Im using LEFT(A2,3). Once it recognizes the first 3 digits, I need it to look at the corresponding SHEET and then search column "A" for the matching part number and return the value in column "B" for the description.

I've tried nested if statements with vlookup and with INDEX/MATCH but I cant seem to get it to work. There are 16 different categories now, so thats a lot of nesting.

Can someone help me with this or even recommend a different approach? I'm in a bit over my skill level with this.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
It would help if you renamed the category sheets to something consistant, like "Category 101" "Category 102" etc.

Then

=VLOOKUP(A2, INDIRECT("'Category "&LEFT(A2,3)&"'!$A:$B"), 2, FALSE)

could be used.
 
Upvote 0
It would help if you renamed the category sheets to something consistant, like "Category 101" "Category 102" etc.

Then

=VLOOKUP(A2, INDIRECT("'Category "&LEFT(A2,3)&"'!$A:$B"), 2, FALSE)

could be used.

Mike, thank you. I'll be ok with the category names as they are, and the issue is the nesting to recognize the difference between the 16 different categories. It needs to look up on a different page depending on those first 3 numbers.

How can this be done with multiple if statements/lookups nested in 1 formula? Or any other way that would work?
 
Upvote 0
The problem is that each part number references only the three digit start, e.g. "101".

To search the sheets to find out which sheet name starts with "101" takes VBA if there are different endings to the sheet names, e.g. "101 PPE" "102 Soil"
If each sheet has the same ending, like "101 category" "102 category", then the built in INDIRECT can handle it.

With varying sheet name suffixes, you will need VBA. There is no native Excel solution.
 
Upvote 0
Thank you Mike,

So I can change the sheet names to make it work. I have a question about indirect, is it limited? I ask between the 16 different sheets, there are thousands of products. Will INDIRECT still work?

Could you help with the VBA option?
 
Upvote 0
The UDF solution might involve something like

Code:
Function IndirectSheetPrefix(byVal SheetPrefix as String, byVal RangeAddress as String, Optional WorkbookName as String) As Range
    Dim wb as Workbook, ws as WorkSheet
    Application.Volatile

    SheetPrefix = LCase(SheetPrefix)
    If WorkbookName = vbNullString Then
        set wb = ThisWorkbook
    Else
        Set wb = Workbooks(WorkBookName)
    End If

    For Each ws in wb.Worksheets
        If LCase(ws.Name) Like SheetPrefix & "*" Then
            Set IndirectSheetPrefix = ws.Range(RangeAddress)
            Exit For
        End If
    Next ws
End Function

And a formula like
=VLOOKUP(A2, IndirectSheetPrefix(LEFT(A2,3), "$A:$B"), 2, FALSE)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top