Extract numeric value from cell equivalent to COlumn header

surkdidat

Well-known Member
Joined
Oct 1, 2011
Messages
579
Office Version
  1. 2016
Hi
I have data in a cell (see initial data) where I want to be able to split out the numeric values out as per the column header.

I would be looking at putting the animal (in this example) and would want the "quantity" before the "x"


Initial dataHorsesCatsDogsWhite RhinosAfrican elephantsIndian elephants
2x horses, 129x cats, 30x dogs, 18x white rhinos21293018
2x cats, 19x White Rhinos, 3260x African elephants, 1x Indian elephant21932601
45x Dogs45
 
Last edited by a moderator:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
How about
Fluff.xlsm
ABCDEFG
1Initial dataHorsesCatsDogsWhite RhinosAfrican elephantsIndian elephants
22x horses, 129x cats, 30x dogs, 18x white rhinos21293018  
32x cats, 19x White Rhinos, 3260x African elephants, 1x Indian elephant 2 193260 
445x Dogs  45   
Main
Cell Formulas
RangeFormula
B2:G4B2=IFERROR(FILTERXML("<k><m>"&SUBSTITUTE(SUBSTITUTE(LOWER($A2),",","x "),"x ","</m><m>")&"</m></k>","//m[.='"&LOWER(B$1)&"']/preceding::m[1]"),"")


But the header values must be an exact match as can be seen in G3
 
Upvote 2
Book1
ABCDEFG
1Initial dataHorsesCatsDogsWhite RhinosAfrican elephantsIndian elephants
22x horses, 129x cats, 30x dogs, 18x white rhinos21293018  
32x cats, 19x White Rhinos, 3260x African elephants, 1x Indian elephant 2 193260 
445x Dogs  45   
Sheet4
Cell Formulas
RangeFormula
B2:G4B2=IFERROR(--SUBSTITUTE(FILTERXML("<t><s>"&SUBSTITUTE(UPPER($A2),", ","</s><s>")&"</s></t>","//s[translate(.,'0123456789','')='X "&UPPER(B$1)&"']"),"X "&UPPER(B$1),),"")
 
Upvote 1
Thank you - is there anyway it could have the header as the singular and have a wildcard after so it picks up on both the singular
and plural versions at all please?
Book1
ABCDEFG
1Initial dataHorsesCatsDogsWhite RhinosAfrican elephantsIndian elephants
22x horses, 129x cats, 30x dogs, 18x white rhinos21293018  
32x cats, 19x White Rhinos, 3260x African elephants, 1x Indian elephant 2 193260 
445x Dogs  45   
Sheet4
Cell Formulas
RangeFormula
B2:G4B2=IFERROR(--SUBSTITUTE(FILTERXML("<t><s>"&SUBSTITUTE(UPPER($A2),", ","</s><s>")&"</s></t>","//s[translate(.,'0123456789','')='X "&UPPER(B$1)&"']"),"X "&UPPER(B$1),),"")
How about
Fluff.xlsm
ABCDEFG
1Initial dataHorsesCatsDogsWhite RhinosAfrican elephantsIndian elephants
22x horses, 129x cats, 30x dogs, 18x white rhinos21293018  
32x cats, 19x White Rhinos, 3260x African elephants, 1x Indian elephant 2 193260 
445x Dogs  45   
Main
Cell Formulas
RangeFormula
B2:G4B2=IFERROR(FILTERXML("<k><m>"&SUBSTITUTE(SUBSTITUTE(LOWER($A2),",","x "),"x ","</m><m>")&"</m></k>","//m[.='"&LOWER(B$1)&"']/preceding::m[1]"),"")


But the header values must be an exact match as can be seen in G3
 
Upvote 0
You could use
Excel Formula:
=IFERROR(FILTERXML("<k><m>"&SUBSTITUTE(SUBSTITUTE(LOWER($A2),",","x "),"x ","</m><m>")&"</m></k>","//m[contains(.,'"&LOWER(B$1)&"')]/preceding::m[1]"),"")
 
Upvote 1
Solution
Thank you once again Fluff, and also to JvdV - your help is very much appreciated :) :) :)
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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