AOCREPLACE

=AOCREPLACE(a,d,rd,oc)

a
array
d
any string or delimiter
rd
any string , replacement delimiter
oc
occurrence values to be replaced, 0 or ignored, repaces all occurrences, selective occurrences as constant integers row array {2,4,5} or single values , 2, 4, values out of range are ignored

AOCREPLACE, array occurrences replace, replaces only certain occurrences "oc" of a delimiter(any string) "d" in array "a", with a replacement delimiter(any string) "rd"

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
860
Office Version
  1. 365
Platform
  1. Windows
AOCREPLACE !! recursive !! array occurrences replace, replaces only certain occurrences "oc" of a delimiter(any string) "d" in array "a", with a replacement delimiter(any string) "rd"
Excel Formula:
=LAMBDA(a,d,rd,oc,
    LET(y,SORT(UNIQUE(oc,1),,,1),o,FILTER(y,y>0,0),n,COLUMNS(o),x,INDEX(o,1,n),
       IF(n=1,IF(o=0,SUBSTITUTE(a,d,rd),SUBSTITUTE(a,d,rd,x)),AOCREPLACE(SUBSTITUTE(a,d,rd,x),d,rd,INDEX(o,1,SEQUENCE(,n-1))))
    )
)
LAMBDA 6.0.xlsx
ABCDEFGHIJK
1Sample
219/3/2021/ES-3765/Tv-LG345/375extract values with ASPLITASPLIT
320/3/2021/FR-5545678/Mobile-SM76345/1233=AOCREPLACE(A2:A4,"/","|",{3,4,5})=ASPLIT(C4#,"|")
421/3/2021/AG-465/Audio-BO6345/198019/3/2021|ES-3765|Tv-LG345|37519-03-21ES-3765Tv-LG345375
520/3/2021|FR-5545678|Mobile-SM76345|123320-03-21FR-5545678Mobile-SM763451233
6=AOCREPLACE(A2:A4,"/","|",)21/3/2021|AG-465|Audio-BO6345|198021-03-21AG-465Audio-BO63451980
719|3|2021|ES-3765|Tv-LG345|375
820|3|2021|FR-5545678|Mobile-SM76345|1233year in a separate column
921|3|2021|AG-465|Audio-BO6345|1980=AOCREPLACE(A2:A4,"/","|",{2,3,4,5})=ASPLIT(C10#,"|")
1019/3|2021|ES-3765|Tv-LG345|37519-03-212021ES-3765Tv-LG345375
11=AOCREPLACE(A2:A4,"/","|",{-3,0,2,2,4,7})20/3|2021|FR-5545678|Mobile-SM76345|123320-03-212021FR-5545678Mobile-SM763451233
1219/3|2021/ES-3765|Tv-LG345/37521/3|2021|AG-465|Audio-BO6345|198021-03-212021AG-465Audio-BO63451980
1320/3|2021/FR-5545678|Mobile-SM76345/1233
1421/3|2021/AG-465|Audio-BO6345/1980extract everything except dates
15=AOCREPLACE(A2:A4,"-","/",)=ASPLIT(AOCREPLACE(C16#,"/","|",{3,4,5,6,7}),"|")
1619/3/2021/ES/3765/Tv/LG345/37519-03-21ES3765TvLG345375
1720/3/2021/FR/5545678/Mobile/SM76345/123320-03-21FR5545678MobileSM763451233
1821/3/2021/AG/465/Audio/BO6345/198021-03-21AG465AudioBO63451980
19
20=AOCREPLACE(AOCREPLACE(A21:A24,"//","|",),"/"," ",)=ASPLIT(C21#,"|")
21aa//gf//bh//nm/ng/dghf/gfaa|gf|bh|nm ng dghf gfaagfbhnm ng dghf gf
22aa//gf//bh//nm/ng/dghf/gfaa|gf|bh|nm ng dghf gfaagfbhnm ng dghf gf
23aa//gf//bh//nm/ng/dghf/gfaa|gf|bh|nm ng dghf gfaagfbhnm ng dghf gf
24aa//gf//bh//nm/ng/dghf/gfaa|gf|bh|nm ng dghf gfaagfbhnm ng dghf gf
25
AOCREPLACE post
Cell Formulas
RangeFormula
C3,C20,E20,C15,E15,A11,C9,E9,A6,E3C3=FORMULATEXT(C4)
C4:C6C4=AOCREPLACE(A2:A4,"/","|",{3,4,5})
E4:H6,E21:H24,E10:I12E4=ASPLIT(C4#,"|")
A7:A9A7=AOCREPLACE(A2:A4,"/","|",)
C10:C12C10=AOCREPLACE(A2:A4,"/","|",{2,3,4,5})
A12:A14A12=AOCREPLACE(A2:A4,"/","|",{-3,0,2,2,4,7})
C16:C18C16=AOCREPLACE(A2:A4,"-","/",)
E16:J18E16=ASPLIT(AOCREPLACE(C16#,"/","|",{3,4,5,6,7}),"|")
C21:C24C21=AOCREPLACE(AOCREPLACE(A21:A24,"//","|",),"/"," ",)
Dynamic array formulas.
 
Last edited by a moderator:
Upvote 0
Note: The following Lambda function is used in the sample mini-sheet above are explained on the following page:
ASPLIT
 

Forum statistics

Threads
1,223,575
Messages
6,173,148
Members
452,502
Latest member
PQCurious

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