How do I remove leading or trailing spaces of all cells in an entire column?
The worksheet's conventional Find and Replace (aka Ctrl+H) dialog is not solving the problem.
Quite often the issue is a non-breaking space - CHAR(160) - especially from Web text sources -that CLEAN can't remove, so I would go a step further than this and try a formula like this which replaces any non-breaking spaces with a standard one
=TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," ")))
Ron de Bruin has an excellent post on tips for cleaning data here
You can also remove the CHAR(160) directly without a workaround formula by
Edit .... Replace your selected data,
in Find What hold ALT and type 0160 using the numeric keypad
Leave Replace With as blank and select Replace All
If you would like to use a formula, the TRIM function will do exactly what you're looking for:
+----+------------+---------------------+
| | A | B |
+----+------------+---------------------+
| 1 | =TRIM(B1) | value to trim here |
+----+------------+---------------------+
So to do the whole column...
1) Insert a column
2) Insert TRIM function pointed at cell you are trying to correct.
3) Copy formula down the page
4) Copy inserted column
5) Paste as "Values"
Should be good to go from there...
Without using a formula you can do this with 'Text to columns'.
Select the column that has the trailing spaces in the cells.
Click 'Text to columns' from the 'Data' tab, then choose option 'Fixed width'.
Set a break line so the longest text will fit. If your largest cell
has 100 characters you can set the breakline on 200 or whatever you
want.
Finish the operation.
You can now delete the new column Excel has created.
The 'side-effect' is that Excel has removed all trailing spaces in the original column.
If it's the same number of characters at the beginning of the cell each time, you can use the text to columns command and select the fixed width option to chop the cell data into two columns. Then just delete the unwanted stuff in the first column.
I've found that the best (and easiest) way to delete leading, trailing (and excessive) spaces in Excel is to use a third-party plugin. I've been using ASAP Utilities for Excel and it accomplishes the task as well as adds many other much-needed features. This approach doesn't require writing formulas and can remove spaces on any selection spanning multiple columns and/or rows. I also use this to sanitize and remove the uninvited non-breaking space that often finds its way into Excel data when copying-and-pasting from other Microsoft products.
More information regarding ASAP Utilities and trimming can be found here:
http://www.asap-utilities.com/asap-utilities-excel-tools-tip.php?tip=87
I was able to use Find & Replace with the "Find what:" input field set to:
" * "
(space asterisk space with no double-quotes)
and "Replace with:" set to:
""
(nothing)
Related
I have 100's of rows of data, each row containing a list of multiple items separated by comma. for example:
a fox, a frog, a dog, candy,
tyler, daren, hogge, laura,
cat in the hat, remembering your favorite day, having a fun time
etc
as you can see, its not a simple "lastname, firstname" separation.
the issue im having is when i use text to columns, i can easily separate by comma, but im then left with a space before every second item in the list. I need to remove the space after each comma (but not EVERY space after each word!)
I cant just select "comma" and "space" in the delimiters option, because then it removes EVERY space between words (eg 'havingafuntime') when i only want to remove THE ONE space after the comma.
I know i can use "trim" - but im wondering if theres a way to remove the space WHILE SEPARATING THE TEXT TO COLUMNS, all in one swoop.
When working "normal" with excel you can simply left out any formulas for this case.
Instead of the =SUBSTITUTE(A1,", ",",") you can simply select the range you want to be corrected (like the whole A:A column) and press Ctrl+H (replace). Set "Find What" to ", " and "replace with" to "," (without the "). Hit replace all the to do it for the whole selection (non selected cells won't be replaced).
The build-in "Text to columns" can not be manipulated in a way to do it in one step.
EDIT:
Doing it as a one-click-macro just this 4 lines should do what you desire:
Sub text2cols()
Selection.Replace ", ", ","
Selection.TextToColumns Selection.Resize(1, 1), 1, , , , , True
End Sub
Just select the range you want to seperate and run the macro ;)
in the cell adjacent to the start of the column you are going to convert using text to columns, enter the following formula and copy down.
=substitute(A1,", ",",")
This will remove the space after every ,
Then copy and paste as value the resulting column.
Then perform your Text to Columns operation using , as you delimiter.
Another option would be to use Power Query.
Depending on your version of excel you should be able to download an install Power Query by googling "Download Power query for Excel 20X"
click in your data set
On Power query tab you will see "From Table" (in excel 2016 its already in data tab, you do not have to download it)
choose if your data has header or not
Go to Transform
Under Split column choose by delimiter
Choose comma
Under Format you will see Trim
Go to Home tab choose close and load
and you're done
I know this is an old post, but I found this doing a google search because I had the same problem as the OP. However, upon reading some of the suggestions it came to me that I can use the Find & Replace feature. I selected the column in question and did the following:
Find what: ", " (without quotes - used to show space)
Replace with: , (no space)
Essentially this made the list go from: a fox, a frog, a dog, candy, tyler, daren, hogge, laura, cat in the hat, remembering your favorite day, having a fun time
And changed it into this: a fox,a frog,a dog,candy,tyler,daren,hogge,laura,cat in the hat,remembering your favorite day,having a fun time
Then I just used the Text To Column function delimited by comma and it worked beautifully.
I hope this helps someone else out.
Is there a way to add a blank column to a query in Query Studio? I tried to use a calculation on an existing column but the only options that I get are for First Characters, Last Characters, Concatenation, and Remove Trailing Spaces. None of these options allow you to enter a decode, case or IF statement.
Any assistance is greatly appreciated. Thanks.
It's a bit of a hack as Query Studio is really all about making it easy to get data and doing anything with layout is really a job for Report Studio, but you can do the following:
a) create a calculated column on a text field. Select 'Concatenation' as the operation and put a space as the preceding text. Click ok
b1) right-click on the new column and select 'Format', then 'Text' and enter 1 for the number of characters
or
b2) create another calculated column from the first calculated column, set it to 'first characters' and enter 1 for the number of characters. The first calculated column can now be deleted.
Both of these approaches will give a column that only contains a single space - not actually blank but close enough for most purposes. The first approach is a little quicker but may result in the text still existing in some output versions (e.g. csv) - I'd need to do more testing to confirm.
The column title can be edited (to be set to blank) by double clicking it, of course.
I need to delete all text to the right of the first "|" in a group of cells.
I had been using this:
=IFERROR(RIGHT(input,LEN(input)-FIND("stack",input)+1),"")
to delete to the left of a specific character. I found this in a stackoverflow question.
I am not sure how to make it so it reads to find the FIRST specific character. I also am trying to delete to the right of, but I believe I can fix that myself.
Thanks in advance
Assuming by the first "|" in a group of cells you mean the leftmost pipe character in each cell of an array of cells then as #Aprillion suggests =LEFT(A1,FIND("|",A1)-1) seems a good approach (where A1 is the first element of the array and the formula is copied across/down as appropriate).
If the group is a column, an alternative could be to use Data > Data Tools – Text to Columns with Delimited and Other: |, then delete inserted columns as required.
Ive pasted a large list of data into column A in a excel sheet, all the data has come in with a space after the text ie. 'text ', 'some more text '..
I need to clear away this last space, as an approach i tried to find/replace all spaces, but that left me with a load of text strings like 'somemoretext' as it also deleted all the spaces in between words, any idea how i should handle this ?
TRIM
In Microsoft Excel, the TRIM function returns a text value with the leading and trailing spaces removed.
Or you can still use Find and Replace option: Find "text " Replace "text".
You can use logical approach: check last character
(right(cell;1))
=IF(RIGHT(A3;1)=" ";LEFT(A3;LEN(A3)-1);A3)
If an space exists at the end, it will return the string -1 character (the space)
if there isn't a space, it will return the text without change
You can also remove leading and trailing spaces from column name with this method.
Remove Leading and Trailing Whitespace from Excel Cells
See my answer there.
I really tried a LOT with in-built functions and also with google search but none of the ways doesn't worked out for expected result.
My exact problem is:
I've few numeric columns which i got from a website and copied directly into excel.
In those columns there is a SINGLE Leading space at the beginning of each number in the cell of the entire column. Example 523946.00. In this number there is a single space before the digit 5.
I tried a lot with TRIM and SUBSTITUTE in-built functions but nothing able to resolve my problem of removing spaces.
And also my expectation is when i select two or multiple cells in the same column(spaces removed) then automatically Excel should show or display the AVERAGE: <Average value> SUM: <total Sum> COUNT: <count value> at the below status bar or bottom ribbon.
Say, AVERAGE: 175.49 COUNT: 2 SUM: 350.98
This type of information is not showing at the bottom. Only i'm able to see COUNT: 2 alone....why?
I want in General Format only. No any special formats.
I'm using MS Excel 2013
Edit:
You can actually just use find and replace.
Copy one of the trouble cells.
Select all the cells containing non break space, and select find and replace.
Paste the copied cell into the find bar, delete everything but the last character (asuming that is the non breaking space).
Leave the replace bar empty and press replace all.
This removes all non breaking spaces. :)
**Old Solution:**You can add nothing with paste special to the whole column where the spaces occur.
First copy an completely empty cell. (! remember this step)
Then select all cells in the column and right click and select paste special.
Then select "add" almost at the bottom (see picture) and press ok.
This will make excel reevaluate the values as if you had modified in and entered the value manually. Excel then correctly converts them to numbers. :)
First make sure you have the column Formatted as you would like. Make sure it is a number with 2 decimal places (or how ever many you need), then also make sure that there is no Indents (Maybe you think the Indent is a space?) And that you have it Aligned to the Left, Or where you want the Data To be. This alone should take care of your issue.
If that doesn't work here a list of possible solutions.
=Value(Trim(A1)) ' Removes all white space before and after the text in A1
=Value(Clean(A1)) 'Removes all non printable Charactersin A1
=Value(SUBSTITUTE(I3," ","")) 'Substitutes(Replaces) all instances of " "(Space) with ""(nothing)
'****Note: With Substitute you can also specify how many
' Substitutes(Replaces) to make of the value
=Value(SUBSTITUTE(I3," ","",1)) ' Same as above but with only remove the FIRST space
=Value(Trim(Clean(A1))) ' Removes all white space before and after the text
' after removing all Non-Printable Characters
=Value(Trim(Clean(Substitute(A1," ","")))) ' Removes all white space before and after the
'after removing all Non-Printable Characters
' And after replaceing all spaces with nothing
=Value(Right(A1, Len(A1)-1)) ' This takes the End of your text by the number of characters
' in the value Except the First (In your case should be the Space)
=Value(SUBSTITUTE(I6,CHAR(160),"")) 'To help with the non breaking spaces also.
If nothing works could you please share Why you would like to remove the space? As in what you are trying to do with the data? As maybe that will open more solutions
With Ole Henrik Skogstrøm's Suggestion added Value around the functions to get the result as a value.
It may be Excel is treating your cells as text data. Is the fun Green Triangle present?
This is a common problem in excel. Forcing numeric is easier than text. Just format a column as number or General and then put in the function value() into the cells.
Things can be cleaned up from there with Copy/Paste Special values and then remove the original column.
Using Excel 2007
brettdj answered this for me. This is what worked for me and it was SIMPLE!!
To remove the CHAR(160) directly without a workaround formula go to
Find & Replace
in the Find What hold ALT and type 0160 using the numeric keypad
then Leave Replace With as blank and select Replace All
In your case, since you always have a string of numbers, where you want to remove just the first character (a space), this formula should work:
=RIGHT(A1,LEN(A1)-1)
The numbers can vary in length, important is only, that you want to remove just 1, (or 2, or 3 etc) characters. It will still work. {If you had 2 empty spaces in front, then you would use in the formula -2, if three -3, etc)
However, if you had always a different amount of blanks in your string of numbers, like I had, you could use this formula, which worked for me:
=VALUE(SUBSTITUTE(TRIM(A1),CHAR(160),""))
,assuming that the issue you are facing is code "160".
That you can find by typing: =code(A1), which in my case gave me the result "160". Therefore char(160) in the formula above.