ATRIM

=ATRIM(Array,Delimiter)

Array
Required. Array to remove extra delimiters and non-printing characters.
Delimiter
Optional. Text separator to remove; ignored = space

ATRIM combines TRIM and CLEAN and removes all extra delimiters in text strings (like TRIM for spaces) and removes all non-printing characters listed in CLEAN.

schardt679

Board Regular
Joined
Mar 27, 2021
Messages
58
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
ATRIM combines TRIM and CLEAN and removes all extra delimiters in text strings (like TRIM for spaces) and removes all non-printing characters listed in CLEAN.
It converts ASCII delete characters (CHAR 127) to empty strings and non-breaking spaces (CHAR 160) spaces (CHAR 32). Thanks to Xlambda and their ATRIM for the inspiration.

Excel Formula:
=LAMBDA(Array,Delimiter,
      LET(Arr, Array,
          Del, Delimiter&"",
          Sp, " ",
          C_127, CHAR(127),
          C_160, CHAR(160),
          No_C127, SUBSTITUTE(CLEAN(Arr), C_127, ""),
          No_C160, SUBSTITUTE(No_C127, C_160, Sp),
          DelToC127, TRIM(SUBSTITUTE(No_C160, Del, C_127)),
          SpToC160, SUBSTITUTE(DelToC127, Sp, C_160),
          C127ToSp, TRIM(SUBSTITUTE(SpToC160, C_127, Sp)),
          SpToDel, SUBSTITUTE(C127ToSp, Sp, Del),
          Return, SUBSTITUTE(SpToDel, C_160, Sp),
          Return
      )
 )
LAMBDA Examples.xlsx
ABCDEFGHI
1ATRIM
2
3Original DataResult
4ProductSalesDateProductSalesDate
5Pepper Deseeder 1903/22/21Pepper Deseeder1903/22/21
6Knife Set4 03/22/21Knife Set403/22/21
7Cutting Board703/22/21Cutting Board744277
8Pepper Deseeder#N/A03/23/21 Pepper Deseeder#N/A03/23/21
9Knife Set 2803/23/21Knife Set2844278
10Cutting Board1603/23/21Cutting Board1603/23/21
11 Pepper Deseeder03/24/21Pepper Deseeder44279
12
13Delimiter is space
14Formula in cell F4☛ =ATRIM(B4:D11,)
15
16
17
18Original DataResult
19DateDate
2003/22///2103/22/21
21#VALUE!#VALUE!
2203//22///2103/22/21
2303//23/21 03/23/21
24
2503/23/2103/23/21
2603/24/2144279
27
28Delimiter is slash
29Formula in cell D19☛ =ATRIM(B19:B26, "/")
30
31
32
33Original DataResult
34Group||Project|||Start By||||End ByGroup|Project|Start By|End By
351||||A|||3/22/21|||3/23/211|A|3/22/21|3/23/21
36
37#VALUE!#VALUE!
382|||||B2|||||3/22/21|||||3/25/212|B2|3/22/21|3/25/21
393||C|||3/23/21||||3/25/213|C|3/23/21|3/25/21
404||||D|||3/23/21||||3/23/214|D|3/23/21|3/23/21
415||||E1|||||3/23/21||||3/26/215|E1|3/23/21|3/26/21
425||||E2||||||3/24/21|||3/29/215|E2|3/24/21|3/29/21
435||||||E3||3/25/21|||3/30/215|E3|3/25/21|3/30/21
44
45Delimiter is pipe
46Formula in cell D34☛ =ATRIM(B34:B43, "|")
47
48
49
50Original DataResult
51Group||Project|||Start By||||End ByGroup||Project|||Start By||End By
521||||A|||3/22/21|||3/23/211||A|||3/22/21|||3/23/21
53
54#VALUE!#VALUE!
552|||||B2|||||3/22/21|||||3/25/212|||B2|||3/22/21|||3/25/21
563||C|||3/23/21||||3/25/213||C|||3/23/21||3/25/21
574||||D|||3/23/21||||3/23/214||D|||3/23/21||3/23/21
585||||E1|||||3/23/21||||3/26/215||E1|||3/23/21||3/26/21
595||||E2||||||3/24/21|||3/29/215||E2||3/24/21|||3/29/21
605||||||E3||3/25/21|||3/30/215||E3||3/25/21|||3/30/21
61
62Delimiter is pipe
63Formula in cell D51☛ =ATRIM(B51:B60, "||")
64
ATRIM
Cell Formulas
RangeFormula
F4:H11F4=ATRIM(B4:D11,)
C8C8=NA()
B14B14=AFORMULATEXT(F4)
D19:D26D19=ATRIM(B19:B26, "/")
B21,B54,B37B21=1+"A"
B29B29=AFORMULATEXT(D19)
D34:D43D34=ATRIM(B34:B43, "|")
B46,B63B46=AFORMULATEXT(D34)
D51:D60D51=ATRIM(B51:B60, "||")
Dynamic array formulas.
 
Upvote 0
ATRIM has been updated to include the optional argument syntax. The Delimiter argument is now truly optional. If omitted or left blank, a space will be used.


ATRIM combines TRIM and CLEAN to remove all extra delimiter characters in text strings (like TRIM for spaces) and remove all non-printing characters listed in CLEAN.

Thanks to XLambda's ATRIM for the inspiration.
Similar to other Excel text functions, values are returned as text.
ASCII delete characters (CHAR 127) ⇨ empty strings and non-breaking spaces (CHAR 160) ⇨ spaces (CHAR 32).
Calls IFBLANK.
Other functions on minisheet: AFORMULATEXT.

Screen Tip/ Comment: =ATRIM(Array☛ range to trim & clean, [Delimiter]☛ separator; ❎=" "✅) ⁂[]=optional; ✅=default; ❎=omit

Syntax: ATRIM(Array,[Delimiter])

Arguments:
Array: Required. Array to remove extra delimiters and non-printing characters.
[Delimiter]: Optional. Value separator(s); ignored☛ space. Can be multiple separators but the row/ column count must match array.

Excel Formula:
=LAMBDA(Array,[Delimiter],
      LET(Arr, Array,          Sp, " ",          Del, IFBLANK(Delimiter, Sp),
             C_127, CHAR(127),          C_160, CHAR(160),          No_C127, SUBSTITUTE(CLEAN(Arr), C_127, ""),
             No_C160, SUBSTITUTE(No_C127, C_160, Sp),          DelToC127, SUBSTITUTE(No_C160, Del, C_127),
             SpToC160, SUBSTITUTE(DelToC127, Sp, C_160),          C127ToSp, TRIM(SUBSTITUTE(SpToC160, C_127, Sp)),
             Result, SUBSTITUTE(C127ToSp, Sp, Del),          Return, SUBSTITUTE(Result, C_160, Sp),
             Return
      )
  )
LAMBDA Examples.xlsx
ABCDEFGHIJK
1ATRIM
2
3Original DataDelimiterResult
4ProductSalesDateProductSalesDate
5Pepper Deseeder 1903/22/21Pepper Deseeder1903/22/21
6Knife Set4 03/22/21Knife Set403/22/21
7Cutting Board703/22/21Cutting Board744277
8Pepper Deseeder#N/A03/23/21 Pepper Deseeder#N/A03/23/21
9Knife Set 2803/23/21Knife Set2844278
10Cutting Board1603/23/21Cutting Board1603/23/21
11 Pepper Deseeder03/24/21Pepper Deseeder44279
12
13Delimiter is space
14Formula in cell H4☛ =ATRIM(B4:D11)
15
ATRIM
Cell Formulas
RangeFormula
H4:J11H4=ATRIM(B4:D11)
C8C8=NA()
B14B14=AFORMULATEXT(H4)
Dynamic array formulas.
 

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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