SKU Generator From Various URLs - Different Syntax

censo

Board Regular
Joined
Dec 25, 2015
Messages
109
CURRENT SCENARIO

The functions below create a custom SKU based on a hard-coded supplier and its respective URL syntax

<b>Excel 2013 32 bit</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5" /><col /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="font-weight: bold;text-align: center;;">Example</td><td style="font-weight: bold;;">SUPP URL</td><td style="font-weight: bold;;">CUSTOM SKU Output</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: center;;">1</td><td style=";">https://www.walmart.com/ip/33857317</td><td style=";">WAL-33857317</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: center;;">2</td><td style=";">https://www.walmart.com/ip/Mainstays-Metal-Canopy-Bed-Multiple-Colors-Multiple-Sizes/126889322</td><td style=";">WAL-126889322</td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: center;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: center;;">3</td><td style=";">https://www.costco.com/Aquaterra-Spas-Ventura-96-jet%2c-6-person-Spa.product.100355896.html</td><td style=";">COS-100355896</td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style="text-align: center;;">4</td><td style=";">https://www.costco.com/Urban-Islands-304-Stainless-Steel-5-burner-Grill.product.100075481.html</td><td style=";">COS-100075481</td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style="text-align: center;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style="text-align: center;;">5</td><td style=";">https://www.samsclub.com/sams/118235.ip</td><td style=";">SAM-118235</td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style="text-align: center;;">6*</td><td style=";">https://www.samsclub.com/sams/oif-vertical-file-cabinet-4-drawer-economy-letter-26-1-2-black/prod5380361.ip</td><td style=";">SAM-black/prod5380361</td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="text-align: center;;">7*</td><td style=";">https://www.samsclub.com/sams/chair-leather-coil-b/prod12930214.ip?xid=cat1838-offi:carousel-save-on-office-chairs:2:4</td><td style=";">SAM-on-office-chairs:</td></tr></tbody></table><p style="width:2.4em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5;color: #161120">DATA</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #BBB"><thead><tr style=" background-color: #DAE7F5;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">C2</th><td style="text-align:left">=IF(<font color="#0000FF">B2<>"","WAL-"&TRIM(<font color="#FF0000">RIGHT(<font color="#00FF00">SUBSTITUTE(<font color="#800080">B2,"/",REPT(<font color="#008080">" ",LEN(<font color="#FF00FF">B2</font>)</font>)</font>),LEN(<font color="#800080">B2</font>)</font>)+0</font>),""</font>)</td></tr><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">C3</th><td style="text-align:left">=IF(<font color="#0000FF">B3<>"","WAL-"&TRIM(<font color="#FF0000">RIGHT(<font color="#00FF00">SUBSTITUTE(<font color="#800080">B3,"/",REPT(<font color="#008080">" ",LEN(<font color="#FF00FF">B3</font>)</font>)</font>),LEN(<font color="#800080">B3</font>)</font>)+0</font>),""</font>)</td></tr><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">C5</th><td style="text-align:left">=IF(<font color="#0000FF">B5<>"","COS-"&LEFT(<font color="#FF0000">TRIM(<font color="#00FF00">RIGHT(<font color="#800080">SUBSTITUTE(<font color="#008080">B5,".product.",REPT(<font color="#FF00FF">" ",20</font>)</font>),20</font>)</font>),LEN(<font color="#00FF00">TRIM(<font color="#800080">RIGHT(<font color="#008080">SUBSTITUTE(<font color="#FF00FF">B5,".product.",REPT(<font color="#000080">" ",20</font>)</font>),20</font>)</font>)</font>)-5</font>),""</font>)</td></tr><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">C6</th><td style="text-align:left">=IF(<font color="#0000FF">B6<>"","COS-"&LEFT(<font color="#FF0000">TRIM(<font color="#00FF00">RIGHT(<font color="#800080">SUBSTITUTE(<font color="#008080">B6,".product.",REPT(<font color="#FF00FF">" ",20</font>)</font>),20</font>)</font>),LEN(<font color="#00FF00">TRIM(<font color="#800080">RIGHT(<font color="#008080">SUBSTITUTE(<font color="#FF00FF">B6,".product.",REPT(<font color="#000080">" ",20</font>)</font>),20</font>)</font>)</font>)-5</font>),""</font>)</td></tr><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">C8</th><td style="text-align:left">=IF(<font color="#0000FF">B8<>"","SAM-"&LEFT(<font color="#FF0000">TRIM(<font color="#00FF00">RIGHT(<font color="#800080">SUBSTITUTE(<font color="#008080">B8,"/sams/",REPT(<font color="#FF00FF">" ",20</font>)</font>),20</font>)</font>),LEN(<font color="#00FF00">TRIM(<font color="#800080">RIGHT(<font color="#008080">SUBSTITUTE(<font color="#FF00FF">B8,"/sams/",REPT(<font color="#000080">" ",20</font>)</font>),20</font>)</font>)</font>)-3</font>),""</font>)</td></tr><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">C9</th><td style="text-align:left">=IF(<font color="#0000FF">B9<>"","SAM-"&LEFT(<font color="#FF0000">TRIM(<font color="#00FF00">RIGHT(<font color="#800080">SUBSTITUTE(<font color="#008080">B9,"/sams/",REPT(<font color="#FF00FF">" ",20</font>)</font>),20</font>)</font>),LEN(<font color="#00FF00">TRIM(<font color="#800080">RIGHT(<font color="#008080">SUBSTITUTE(<font color="#FF00FF">B9,"/sams/",REPT(<font color="#000080">" ",20</font>)</font>),20</font>)</font>)</font>)-3</font>),""</font>)</td></tr><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">C10</th><td style="text-align:left">=IF(<font color="#0000FF">B10<>"","SAM-"&LEFT(<font color="#FF0000">TRIM(<font color="#00FF00">RIGHT(<font color="#800080">SUBSTITUTE(<font color="#008080">B10,"/sams/",REPT(<font color="#FF00FF">" ",20</font>)</font>),20</font>)</font>),LEN(<font color="#00FF00">TRIM(<font color="#800080">RIGHT(<font color="#008080">SUBSTITUTE(<font color="#FF00FF">B10,"/sams/",REPT(<font color="#000080">" ",20</font>)</font>),20</font>)</font>)</font>)-3</font>),""</font>)</td></tr></tbody></table></td></tr></table><br />
<insert excel="" file="" here="">
(I don't know why this is coming out all multi-colored)

THE CHALLENGE

The above solution works fine* for a single supplier on a sinble tab; however, when working with various suppliers on the sam tab, challenges are created which are:

- SKU prefixes cannot be hardcoded in the function for a single supplier using the current method (i.e., "WAL")
- Different suppliers have different URL syntax


THE DESIRED RESULT

A two-pronged function that:

- identifies the supplier by URL, and builds a SKU beginning with a prefix (ex., "WAL", "COS", "SAM"). The supplier prefix will always be 3 characters in length (references an array - preferably a named list, such as "SUPP_PREFIX")

- then returns the item# from that specific supplier's URL and concatenates the SKU properly with a hyphen separating the two returned values (ex. "WAL-1234567")


SUPPORTING DETAILS

The ability to identify the supplier from a URL will ALWAYS be in between "www." and ".com" - the beginning portion of the URL. This syntax will always be constant and true.

Context Examples:
<supplier><supplier><supplier><supplier><supplier><supplier><supplier><supplier><supplier><supplier><supplier><supplier>www.supplier.com
http://www.supplier.com
https://www.supplier.com

Content Examples:
<item#>www.walmart.com/ip/ITEM#
"walmart" identifies as "WAL"

<item#>https://www.samsclub.com/sams/ITEM#.ip
"samsclub" identifies as "SAM"

<item#>https://www.costco.com/.product.ITEM#.html
"costco" identifies as "COS"

As alluded to above, the function would then reference a secondary array based on:

- a particular supplier's name, and then
- recognize that supplier's syntax to know where to extract the specific item#


SPECIFIC ITEM# LOCATION

The exact location of the suppliers' item# appear in the examples provided above (Content Examples).

I have what appears to be working solutions for Walmart and Costco.

With Sam's Club however, I get mixed results*. On the referenced Excel table above, Examples 6 & 7 return inconsistent results. The output should only be the supplier prefix, hyphen, item# (Ex. SAM-1234567).

Note - the correct SKU output for Example 6 should be: SAM-prod5380361 because that's what appears between the last forward slash and ".ip"

What modification to this function would target only what appears between the last foward slash and ".ip"?


PUTTING IT ALTOGETHER

Functions are not my strong suit but I try my best to understand what they do and with the help of this community, I've been successful in piecing together what works for previous projects.

Below is a function that successfully worked for creating hyperlinks based on evaluating the name of a carrier in the URL. I believe that in this function solves the question about how to identify the supplier in order to determine the supplier prefix but I need help tying it altogether to go a step further and properly concatenate a perfect SKU just by evaluating a URL.


Code:
=IF(A5<>"",VLOOKUP(IF(ISNUMBER(FIND("www.",A5)),MID(A5,FIND("www.",A5)+4,IF(ISNUMBER(FIND(".com",A5,9)),FIND(".com",A5,9),LEN(A5)+1)-FIND("www.",A5)-4),MID(A5,FIND("//",A5)+2,IF(ISNUMBER(FIND("/",A5,9)),FIND("/",A5,9),LEN(A5)+1)-FIND("//",A5)-2)),SUPP_PREFIX,2,0)

My attempts can be seen on the "Reference" tab and the two named lists I've created there; "SUPP_PREFIX" and "SUPP_ITEM".

I see a flaw right away in that in the "Reference" tab specific cell references are coded in and I just don't know how to make that "neutral" or "variable" for a lack of better words.

<b>Excel 2013 32 bit</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5" /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5;text-align: center;color: #161120"><th></th><th>A</th><th>B</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="font-weight: bold;;">SUPPLIER</td><td style="font-weight: bold;;">SUPP CODE</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style=";">walmart</td><td style=";">WAL</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style=";">samsclub</td><td style=";">SAM</td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style=";">costco</td><td style=";">COS</td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="font-weight: bold;;">SUPP CODE</td><td style="font-weight: bold;;">SUPP FUNCTION</td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style=";">WAL</td><td style=";">TRIM(RIGHT(SUBSTITUTE(A1,"/",REPT(" ",LEN(A1))),LEN(A1))+0)</td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style=";">SAM</td><td style=";">LEFT(TRIM(RIGHT(SUBSTITUTE(A1,"/sams/",REPT(" ",20)),20)),LEN(TRIM(RIGHT(SUBSTITUTE(A1,"/sams/",REPT(" ",20)),20)))-3)</td></tr><tr ><td style="color: #161120;text-align: center;">13</td><td style=";">COS</td><td style=";">LEFT(TRIM(RIGHT(SUBSTITUTE(A1,".product.",REPT(" ",20)),20)),LEN(TRIM(RIGHT(SUBSTITUTE(A1,".product.",REPT(" ",20)),20)))-5)</td></tr></tbody></table><p style="width:5.4em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5;color: #161120">REFERENCE</p><br /><br />




I hope this write-up is chocked full of details to clearly express what I need done and I'm happy to actively engage and try solutions you propose.


Thanks!</item#></item#></item#></supplier></supplier></supplier></supplier></supplier></supplier></supplier></supplier></supplier></supplier></supplier></supplier></insert>
 
Last edited:

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Watch MrExcel Video

Forum statistics

Threads
1,095,201
Messages
5,442,996
Members
405,212
Latest member
Arnie58

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top