View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Spaces at the end of data

On Tue, 15 Sep 2009 18:08:02 -0700, sjs wrote:

I'm trying to run a vlookup but the search array has some cells that contain
data in which there is a space at the end. Is there an easy way to remove
the end space when only some of the cells have the space?

tks,
steve


Set up a helper column.

Original Data
A1:

If you don't mind also removing spaces at the beginning; and replacing multiple
consecutive spaces within the string with a single space:

B1: =TRIM(A1)

If you only want to remove the terminal space:

B1: =IF(RIGHT(A1,1) = " ",LEFT(A1,LEN(A1)-1))

If your data came from an HTML document, try:

B1: =SUBSTITUTE(A1,CHAR(160),"")

(or use the Find/Replace tool to replace the nbsp with nothing. To enter that
into the Find bar, while holding down the <alt key, type (sequentially) 0160
on the NUMERIC KEYPAD (not on the numbers above the keyboard). Then release
the <alt key.
--ron