Hello,
I can't find which formula to use in order to separate numbers from text in the following column:
60g
42.5g
227g
355ml
2L
Any thoughts? You help would be deeply appreciated!
Anne-Claire
Hello,
I can't find which formula to use in order to separate numbers from text in the following column:
60g
42.5g
227g
355ml
2L
Any thoughts? You help would be deeply appreciated!
Anne-Claire
there will be other ways, no doubt more elegant...
=--LEFT(A1,SUMPRODUCT(--(ISNUMBER(--MID(SUBSTITUTE(SUBSTITUTE(A1,".",0),",",0),ROW(INDIRECT("1:"&LEN(A1))),1)))))
where A1 holds string... note in the above I've had to make the assumption that "." & "," are valid numerical delimiters (eg 42.5 or 1,002 etc...)
If it's possible that you would have additional numbers beyond the value of interest (eg 42.5g 10a) you would need to adopt a different approach (where you look for the first text character)
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
A user-defined function can do it. Insert this new function into your sheet in the same place regular macros go:
Now this formula will leave only numbers and periods:![]()
Function CleanAll(txt As String) As String With CreateObject("VBScript.RegExp") 'enter all characters to be KEPT into the pattern .Pattern = "[^0-9.]" .Global = True .IgnoreCase = True CleanAll = Application.Trim(.Replace(txt, "")) End With End Function
=CleanAll(A1)
==========
Alt-F11 to open VBEditor
Insert > Module
Paste in code
Alt-Q to exit VBEditor
Save sheet.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks