VBA Multiple Nested IF functions within table

freya306

New Member
Joined
Sep 9, 2015
Messages
5
So I've got a big stock spreadsheet with multiple tabs to seperate catergories and within each tab is a table. each containing items, each with multiple sizes and then the quantity etc.
for example one group of items I have is

Item
Code
Size
Staff Cardigan
34
Staff Cardigan36
Staff Cardigan38
Staff Cardigan40
Staff Cardigan44
Staff Cardigan46

<colgroup><col span="2"><col></colgroup><tbody>
</tbody>

I want the spreadsheet to create a 'code' for each item depending on the item name and size for example for the first item the code would be STFC34.
I can write a single IF function in one cell to calculate that but I have over 500 items on 6 different sheets that I want it to dictate. So is there a VBA or something that I can write that it can generate the code dependant of the item and size.
The if code I have for a single cell is:
=IF(AND(Table1[@Item]="Staff Cardigan",Table1[@Size]=34),"STFC34",IF(AND(Table1[@Item]="Staff Cardigan",Table1[@Size]=36),"STFC36"))
obviously this would work for the first two lines but I would like to write something that could do the whole table in one go!
Please Help! I havent used VBA before so if someone could help to write one if function for the first line then I can copy it to input the codes for each item I want to use.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I'd recommend creating another sheet with the basic translate table. Name it "Translate". Then in column A put the description, and in B put the code. For example:

Staff CardiganSTFC
Button SweaterBTNS
Long PantsLNGP

<tbody>
</tbody>


and so on. Then you can use a VLOOKUP function to create the codes. If your Item column is A, Code is B, and Size is C, it would be:
Code:
=VLOOKUP(A1,Translate!$A:$B500,2,FALSE)&C1
Copy that formula down column B on each of your sheets.
 
Upvote 0
I'd recommend creating another sheet with the basic translate table. Name it "Translate". Then in column A put the description, and in B put the code. For example:

Staff CardiganSTFC
Button SweaterBTNS
Long PantsLNGP

<tbody>
</tbody>


and so on. Then you can use a VLOOKUP function to create the codes. If your Item column is A, Code is B, and Size is C, it would be:
Code:
=VLOOKUP(A1,Translate!$A:$B500,2,FALSE)&C1
Copy that formula down column B on each of your sheets.

Thanks Eric! Very Helpful! now just to create hundreds of unique Codes!
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,945
Members
449,198
Latest member
MhammadishaqKhan

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