=TRIM(text) strip leading and trailing spaces from text in one or more cells

=TRIM(CLEAN(text)) "clean" removes a range of non-printing characters, including line breaks, and returns "cleaned" text

=TRIM(CLEAN(SUBSTITUTE(B1,CHAR(160)," "))) CLEAN is not able to remove all non-printing characters, notably a non-breaking space, which can be appear in Excel as CHAR(160). By adding the SUBSTITUTE function to the formula, you can remove specific characters