PDA

View Full Version : IF statement inside a vlookup?



rcbricker
03-07-2007, 07:38 AM
Can you place an IF statement inside a vlookup?

I have a list of parts that I have to create in a system. It is easier to do if I create a list of materials ahead of time of what components are needed. What I have done is create a part list that contains a list of parts, what the cost, whether they are manufactured or purchased, and what the sub component is if they are manufactured.

This worked great till I ran into my first sub component that contain its own sub components. I am attaching the spreadsheet so everyone can see what I am doing or more to the point trying to do. IF VBA is a better solution that would be great.

What I need is a formula (or VBA if it is better) that brings back the sub-components and their sub-components for each part until the parts tree for the original part number reaches the base purchased sub-parts.

I have the 1st worksheet set up in three different ways. The first one you run into is simply a length calculator and can be ignored.

The second way is the original way I had the spreadsheet working and it works fine for parts with only one sub-component. If a sub-part has more than one sub-component then it doesn't work.

The third section is where I started building what I thought would work, but it is clumsy and only will work nicely if I can place an IF statement that will only bring back a value for a sub-component if one exists otherwise it will remain blank.

What I would like is to have a formula that will auto fill the information IF and only if it exists for each sub-part listing all sub-components ( I need if it exists, cost, whether it is manufactured or purchased, any and all sub-components [followed by the same information as the parent] and vendor).

In the example the cell colored in yellow is a sub-part that has multiple sub-components. Each of those is listed in the Parts list worksheet with their pertinent information.

please ask any questions that you need to. I am happy to stay with formulas if someone can help me to work this out, but VBA is welcome also.

XLGibbs
03-07-2007, 04:56 PM
If understand the probem correctly, the sheet named "Part Chart" checks the "Parts List" sheet ...which is fine, and the problem is when there are subcomponents as in your highlighted example.

So, you need to check the subcomponents invididual subcomponents to see if each of them exist...which is also fine.

What I am unable to track on is exactly how you want the data subsequently displayed... the data as you have it laid out on the Parts Chart is kind of all over the place (I suppose that is what you were describing as sections?)

What you are asking can be done a number of ways, but what is MOST pertinent is how you want it to look.

Can you lay out a format for ONE sequence as you need it?

In general, yes--you can nest functions inside other functions. Every piece of the VLOOKUP could feasibly be another formula, but that isn't very efficient.

As I said, depending on how the final result is needed, would affect the proposed solutions available.

Shazam
03-07-2007, 07:24 PM
I'm taking a guess here. Input formula in worksheet "Part Chart" in cell C4 and custom format 0;-0;;@ and copied down.

=VLOOKUP($B$24,'Part List'!$A$2:$T$1221,ROWS(C$20:C24),0)

Simon Lloyd
03-08-2007, 09:01 AM
Cross posted here and solved http://www.ozgrid.com/forum/showthread.php?p=338403&posted=1#post338403

Regards,
Simon

rcbricker
03-08-2007, 10:56 AM
The cross post was my bad as I saw how many people were veiwing but not responding and I thought VBAExpress was bogged down with work. MY intention was to move the problem over to the other site and did not remember to even check here till the cross post was placed on Excel help. I apologize for not closing this thread at the same time that I started the new thread there.

Aussiebear
03-09-2007, 01:02 AM
There are people here who have put time and effort into this thread only to find you have turned your back on them. Whilst your apology will no doubt be accepted, you have done yourself a disservice and the next time you post a question, there may be a reluctance for people to supply you with an answer.


Ted

rcbricker
03-09-2007, 06:42 AM
I understand the reason for not having the cross-posting, and I apologized. However, I see it as a little harsh if one mistake causes peopel to not help me out. It is not as if I cross posted multiple times or what have you. The mistake won't happen again as I am not one for wasting my time so I am not big on making others waste theirs. I would hope that you all would understand that and not hold one mistake against me.

mdmackillop
03-09-2007, 06:49 AM
If you get a name as a serial cross-poster, that's when you might start to get ignored, but we're generally a forgiving lot here (I think) and I don't reckon you'll be blacklisted for your first transgression.

moa
03-09-2007, 06:56 AM
I'm sure/hoping no-one holds a grudge here over one mistake.

rcbricker
03-10-2007, 08:17 AM
*Whew*

Cause I use alot of Excel but VBA and heavy strings and formulas seem to be beyond me. I need a lot of help :help