Reduce string length by -1 delimiter at the time

psc1

New Member
Joined
Nov 27, 2011
Messages
32
Office Version
  1. 2010
Hello
Could one of you genius work that one out for me please :)
Trying to break down all strings length in a column by reducing the last value with its delimiter at each step .. all the way down to the last value
I tried to no avail and my head hurts :(

Book1
ABC
1
2Original strings
3a/b/c/d/e/f
4With formula
5a/b/c/d/e
6a/b/c/d
7a/b/c
8a/b
9a
101/2/3/4/5
11With formula
121/2/3/4
131/2/3
141/2
151
16
17
Sheet1
 
If your original strings are scattered down column B and you want to avoid multiple copy/past, perhaps you could use another column for the results, like this where you just enter the first formula and copy down as far as you might need.

21 03 25.xlsm
ABC
1
2
3a/b/c/d/e/fa/b/c/d/e/f
4a/b/c/d/e
5a/b/c/d
6a/b/c
7a/b
8a
9 
101/2/3/4/51/2/3/4/5
111/2/3/4
121/2/3
131/2
141
15 
16 
17aa/bb/cc/ddaa/bb/cc/dd
18aa/bb/cc
19aa/bb
20aa
21 
Reduce by delimiter (2)
Cell Formulas
RangeFormula
C3:C21C3=IF(B3="",IFERROR(LEFT(C2,FIND("\",SUBSTITUTE(C2,"/","\",LEN(C2)-LEN(SUBSTITUTE(C2,"/",""))))-1),""),B3)

Thanks Peter,
This is the right logic to apply :)
I am trying to create missing strings from a list.
I need for all values a, b, c .. their correct path (a=main, a/b=sub, a/b/c=sub ...)
This is the only way the system will accept any upload with the correct path..
Following your logic, in the below example I managed to extract missing (sometimes not) strings in different columns.
I was aiming to regroup all results in a single column and then delete Duplicates...
This should get me the complete list of all links from Main>Sub>...>Sub in their logical order.
Cheers

Book4
ABCDEFGHI
1NameParentPathPath -1Path -1Path -1Path -1
2#REF!ClothesClothes#VALUE!#VALUE!#VALUE!#VALUE!
3MenClothesClothes/MenClothes#VALUE!#VALUE!#VALUE!
4TshirtMenClothes/Men/TshirtClothes/MenClothes#VALUE!#VALUE!
5XLTshirtClothes/Men/Tshirt/XLClothes/Men/TshirtClothes/MenClothes#VALUE!
6This is the correct logical path to upload categories
7
8TshirtWomenClothes/Women/TshirtClothes/WomenClothes#VALUE!#VALUE!
9Some categories pop up without their Parents - so they must be created below
10womenclothesclothes/womenclothes#VALUE!#VALUE!#VALUE!
11ClothesClothes#VALUE!#VALUE!#VALUE!#VALUE!
12
13I must find a way to regroup E,F,G results under D column so the correct path to Main> Sub…>Sub category is restored
14
15
16And then Duplicates will be deleted from this column
17
Sheet1
Cell Formulas
RangeFormula
A10,A8,A2:A5A2=IFERROR(RIGHT(D2,LEN(D2)-FIND("$",SUBSTITUTE(D2,"/","$",LEN(D2)-LEN(SUBSTITUTE(D2,"/",""))))),#REF!)
B10:B11,B8,B2:B5B2=TRIM(LEFT(RIGHT(SUBSTITUTE(D2,"/",REPT(" ",100)),200),100))
E10:H11,E8:H8,E2:H5E2=LEFT(D2,FIND("\",SUBSTITUTE(D2,"/","\",LEN(D2)-LEN(SUBSTITUTE(D2,"/",""))))-1)
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I am afraid your last post has left me more confused. Your original request asked us to start with a "path" and reduce it one "level" at a time... your Column D appears to be the opposite (one "level" building up to a full "path"). Also, I am not completely sure what is existing data and what is calculated data. I think it will make things clear for us if you would post to sheet views... the first of just your existing data (as you see it before you do any processing to it... do not add any comments, just show us what your existing data looks like, nothing more) and the second of what the sheet should look like after all the processing is complete.
 
Upvote 0
I am afraid your last post has left me more confused. Your original request asked us to start with a "path" and reduce it one "level" at a time... your Column D appears to be the opposite (one "level" building up to a full "path"). Also, I am not completely sure what is existing data and what is calculated data. I think it will make things clear for us if you would post to sheet views... the first of just your existing data (as you see it before you do any processing to it... do not add any comments, just show us what your existing data looks like, nothing more) and the second of what the sheet should look like after all the processing is complete.
Hello Rick
Thank you for your feedback and apology for confusing you.
I'll try to explain plainly..
"B" is the existing data "C, D, E" are calculated (-1 value everytime)
In order for me to upload categories in a chronological way (main>sub>...>sub) they must all be present in column "B" under this format:
a
a/b
a/b/c
...
Currently some categories in "B" are listed with the missing links (i.e "B3" missing a - a/b - a/b/c) - Hence formula to extract -1 value all the way to the root.
I intended to recombine results from "C, D, E" into "B" and remove duplicates so I get a complete chronological path to upload.
This is the only way I figured out to get to it..
I hope it makes sense :)

Book1
ABCDE
1Original PathPath -1Path -2Pathe -3
2Antiques-collectables / AdvertisingAntiques-collectables #VALUE!#VALUE!
3Antiques-collectables / Alcohol-related / Beer-related / English-BeerAntiques-collectables / Alcohol-related / Beer-related Antiques-collectables / Alcohol-related Antiques-collectables
4Antiques-collectables / Alcohol-related / Beer-related / NZ-BeerAntiques-collectables / Alcohol-related / Beer-related Antiques-collectables / Alcohol-related Antiques-collectables
5Antiques-collectables / Alcohol-related / Beer-related / OtherAntiques-collectables / Alcohol-related / Beer-related Antiques-collectables / Alcohol-related Antiques-collectables
6Antiques-collectables / Alcohol-related / Beer-related / US-BeerAntiques-collectables / Alcohol-related / Beer-related Antiques-collectables / Alcohol-related Antiques-collectables
7Antiques-collectables / Alcohol-related / OtherAntiques-collectables / Alcohol-related Antiques-collectables #VALUE!
8Antiques-collectables / Alcohol-related / Spirits-related / BourbonAntiques-collectables / Alcohol-related / Spirits-related Antiques-collectables / Alcohol-related Antiques-collectables
9Antiques-collectables / Alcohol-related / Spirits-related / GinAntiques-collectables / Alcohol-related / Spirits-related Antiques-collectables / Alcohol-related Antiques-collectables
10Antiques-collectables / Alcohol-related / Spirits-related / OtherAntiques-collectables / Alcohol-related / Spirits-related Antiques-collectables / Alcohol-related Antiques-collectables
11Antiques-collectables / Alcohol-related / Spirits-related / RumAntiques-collectables / Alcohol-related / Spirits-related Antiques-collectables / Alcohol-related Antiques-collectables
12Antiques-collectables / Alcohol-related / Spirits-related / VodkaAntiques-collectables / Alcohol-related / Spirits-related Antiques-collectables / Alcohol-related Antiques-collectables
13Antiques-collectables / Alcohol-related / Spirits-related / WhiskeyAntiques-collectables / Alcohol-related / Spirits-related Antiques-collectables / Alcohol-related Antiques-collectables
14Antiques-collectables / Alcohol-related / Wine-relatedAntiques-collectables / Alcohol-related Antiques-collectables #VALUE!
15Antiques-collectables / AppliancesAntiques-collectables #VALUE!#VALUE!
16Antiques-collectables / Art-deco-retro / AppliancesAntiques-collectables / Art-deco-retro Antiques-collectables #VALUE!
17Antiques-collectables / Art-deco-retro / ArtAntiques-collectables / Art-deco-retro Antiques-collectables #VALUE!
18Antiques-collectables / Art-deco-retro / Fashion-beautyAntiques-collectables / Art-deco-retro Antiques-collectables #VALUE!
Sheet1
Cell Formulas
RangeFormula
C2:E18C2=LEFT(B2,FIND("\",SUBSTITUTE(B2,"/","\",LEN(B2)-LEN(SUBSTITUTE(B2,"/",""))))-1)
 
Upvote 0
Ah, you wanted the path split out horizontally, not vertically. Give this formula (my original formula with an IFERROR check to suppress the #VALUE! errors from displaying). Put it in cell C2 and copy it across so that the maximum path will be displayed, then copy all those cells down to the bottom of your data.
Excel Formula:
=IFERROR(LEFT(B2,FIND("\",SUBSTITUTE(B2,"/","\",LEN(B2)-LEN(SUBSTITUTE(B2,"/",""))))-1),"")
 
Last edited:
Upvote 0
Solution
Ah, you wanted the path split out horizontally, not vertically. Give this formula (my original formula it an IFERROR check to suppress the #VALUE! errors from displaying). Put it in cell C2 and copy it across so that the maximum path will be displayed, then copy all those cells down to the bottom of your data.
Excel Formula:
=IFERROR(LEFT(B2,FIND("\",SUBSTITUTE(B2,"/","\",LEN(B2)-LEN(SUBSTITUTE(B2,"/",""))))-1),"")
It works perfect :)
I cannot thank you enough (and @Peter_SSs) for your time and expertise.
You guys rock ;)
 
Upvote 0

Forum statistics

Threads
1,215,634
Messages
6,125,938
Members
449,275
Latest member
jacob_mcbride

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