I am trying to solve this problem -
If suppose I have text like this in a single column on Excel
@22-atr$$1 AM**01-May-2015&&
$21-atr@10-Jan-2007*6 PM&
&&56-atr@11 PM$$8-Jan-2016*
**4 PM#68-atr@21-Mar-2022&&
and I want to write functions to have separate columns as follows
Can someone help me do that please?
I am trying to solve this problem and the only thing that I was able to arrive to is extracting Month by using =MID(A1,FIND("-",A1)+1,3)
One option for formulae would be using new functions, currently available in the BETA-channel for insiders:
Formula in B1
:
=LET(A,TEXTSPLIT(A1,{"@","$","&","*","#"},,1),B,SORTBY(A,IFERROR(MATCH(RIGHT(A),{"r","M"},0),3)),C,HSTACK(TAKE(B,,2),TEXTSPLIT(TEXT(--INDEX(B,3),"YYYY-Mmm-D"),"-")),IFERROR(--C,C))
The idea is to:
LET()
throughout to store variables;TEXTSPLIT()
the value in column A using all available delimiters into columns and skip empty values in the resulting array; SORTBY()
the rightmost character of the resulting three elements using MATCH()
. The IFERROR()
will catch the data-string; HSTACK()
the 1st and 2nd column with the result of splitting the 3rd element after we formatted to YYYY-MMM-D
first;Notes :
For fun an UDF using regular expressions:
Public Function GetPart(inp As String, prt As Long) As Variant
Dim Pat As String
Select Case prt
Case 0
Pat = "(\d+-atr)"
Case 1
Pat = "(\d+\s*[AP]M)"
Case 2
Pat = "-(\d{4})"
Case 3
Pat = "-(\w+)-"
Case 4
Pat = "(\d+)-\w+-"
Case Else
Pat = ""
End Select
With CreateObject("vbscript.regexp")
.Pattern = ".*" & Pat & ".*"
GetPart = .Replace(inp, "$1")
End With
End Function
Invoke through =GetPart(0,A1)
. Choices ares 0-4 and in order of your column-headers.
You can achieve what you wish by applying a few simple transformations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.