How to extract data from a cell if three consecutive conditions are met

Slavio

Board Regular
Joined
Mar 28, 2021
Messages
59
Office Version
  1. 365
Platform
  1. Windows
  2. Web
In the column A there are data.
I'm asking for advice.
I need to extract data between two expressions in a string and the condition is met that three lines in a row contain:
1st line "<CATEGORY_ID>"
2nd line "<CATEGORY_NAME>"
3rd line "<CATEGORY_FULLNAME>"

Zošit1
AB
1<SOMETHING>456
2<CATEGORY>Snow chains2
3<CATEGORY_ID>123</CATEGORY_ID>Something .com | Auto-moto | Snow chains
4<CATEGORY_NAME>Snow chains</CATEGORY_NAME>789
5<CATEGORY>LCD to cars
6<CATEGORY_ID>456</CATEGORY_ID>Something .com | Auto-moto | LCD
7<CATEGORY_NAME>Snow chains2</CATEGORY_NAME>
8<CATEGORY_FULLNAME>Something .com | Auto-moto | Snow chains</CATEGORY_FULLNAME>
9</CATEGORY>
10<CATEGORY>
11<CATEGORY_ID>789</CATEGORY_ID>
12<CATEGORY_NAME>Auto</CATEGORY_NAME>
13<CATEGORY>
14<CATEGORY_ID>789</CATEGORY_ID>
15<CATEGORY_NAME>LCD to cars</CATEGORY_NAME>
16<CATEGORY_FULLNAME>Something .com | Auto-moto | LCD</CATEGORY_FULLNAME>
17</CATEGORY>
Sheet1


If there are three consecutive rows with values, then write them down, otherwise do not include them. Simply put, you need data only if the conditions of three rows are met.
Thanks
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Using a helper column, here's what I came up with.
Book1
ABC
1<SOMETHING>456
2<CATEGORY>Snow chains2
3<CATEGORY_ID>123</CATEGORY_ID> Something .com | Auto-moto | Snow chains
4<CATEGORY_NAME>Snow chains</CATEGORY_NAME> 789
5<CATEGORY> LCD to cars
6<CATEGORY_ID>456</CATEGORY_ID>456Something .com | Auto-moto | LCD
7<CATEGORY_NAME>Snow chains2</CATEGORY_NAME>Snow chains2 
8<CATEGORY_FULLNAME>Something .com | Auto-moto | Snow chains</CATEGORY_FULLNAME>Something .com | Auto-moto | Snow chains 
9</CATEGORY>  
10<CATEGORY>  
11<CATEGORY_ID>789</CATEGORY_ID>  
12<CATEGORY_NAME>Auto</CATEGORY_NAME>  
13<CATEGORY>  
14<CATEGORY_ID>789</CATEGORY_ID>789 
15<CATEGORY_NAME>LCD to cars</CATEGORY_NAME>LCD to cars 
16<CATEGORY_FULLNAME>Something .com | Auto-moto | LCD</CATEGORY_FULLNAME>Something .com | Auto-moto | LCD 
17</CATEGORY>  
Sheet1
Cell Formulas
RangeFormula
C1:C17C1=IFERROR(INDEX(B:B,SMALL(IF(B$1:B$17<>"",ROW(B$1:B$17)), ROWS(B$1:B1))), "")
B3:B17B3=IF(AND(LEFT(A3,13)="<CATEGORY_ID>",LEFT(A4,15)="<CATEGORY_NAME>",LEFT(A5,19)="<CATEGORY_FULLNAME>"),MID(A3,SEARCH(">",A3)+1,LEN(A3)-27),IFERROR(IF(AND(LEFT(A2,13)="<CATEGORY_ID>",LEFT(A3,15)="<CATEGORY_NAME>",LEFT(A4,19)="<CATEGORY_FULLNAME>"),MID(A3,SEARCH(">",A3)+1,LEN(A3)-31),IFERROR(IF(AND(LEFT(A1,13)="<CATEGORY_ID>",LEFT(A2,15)="<CATEGORY_NAME>",LEFT(A3,19)="<CATEGORY_FULLNAME>"),MID(A3,SEARCH(">",A3)+1,LEN(A3)-39),""),"")),""))
 
Upvote 0
Solution
Using a helper column, here's what I came up with.
Book1
ABC
1<SOMETHING>456
2<CATEGORY>Snow chains2
3<CATEGORY_ID>123</CATEGORY_ID> Something .com | Auto-moto | Snow chains
4<CATEGORY_NAME>Snow chains</CATEGORY_NAME> 789
5<CATEGORY> LCD to cars
6<CATEGORY_ID>456</CATEGORY_ID>456Something .com | Auto-moto | LCD
7<CATEGORY_NAME>Snow chains2</CATEGORY_NAME>Snow chains2 
8<CATEGORY_FULLNAME>Something .com | Auto-moto | Snow chains</CATEGORY_FULLNAME>Something .com | Auto-moto | Snow chains 
9</CATEGORY>  
10<CATEGORY>  
11<CATEGORY_ID>789</CATEGORY_ID>  
12<CATEGORY_NAME>Auto</CATEGORY_NAME>  
13<CATEGORY>  
14<CATEGORY_ID>789</CATEGORY_ID>789 
15<CATEGORY_NAME>LCD to cars</CATEGORY_NAME>LCD to cars 
16<CATEGORY_FULLNAME>Something .com | Auto-moto | LCD</CATEGORY_FULLNAME>Something .com | Auto-moto | LCD 
17</CATEGORY>  
Sheet1
Cell Formulas
RangeFormula
C1:C17C1=IFERROR(INDEX(B:B,SMALL(IF(B$1:B$17<>"",ROW(B$1:B$17)), ROWS(B$1:B1))), "")
B3:B17B3=IF(AND(LEFT(A3,13)="<CATEGORY_ID>",LEFT(A4,15)="<CATEGORY_NAME>",LEFT(A5,19)="<CATEGORY_FULLNAME>"),MID(A3,SEARCH(">",A3)+1,LEN(A3)-27),IFERROR(IF(AND(LEFT(A2,13)="<CATEGORY_ID>",LEFT(A3,15)="<CATEGORY_NAME>",LEFT(A4,19)="<CATEGORY_FULLNAME>"),MID(A3,SEARCH(">",A3)+1,LEN(A3)-31),IFERROR(IF(AND(LEFT(A1,13)="<CATEGORY_ID>",LEFT(A2,15)="<CATEGORY_NAME>",LEFT(A3,19)="<CATEGORY_FULLNAME>"),MID(A3,SEARCH(">",A3)+1,LEN(A3)-39),""),"")),""))
You're the boss! You are better than artificial intelligence :) Formula in cell B3 worked perfectly.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,143
Members
453,021
Latest member
Justyna P

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