Automatically deleting blank spaces in a cell

Fuerteventura

Board Regular
Joined
Aug 23, 2005
Messages
80
Is there a command which will delete blank spaces in a cell after the text has finished? for example, if the text in the cell is "Test Data ", I would like it to become "Test Data" (deleting the blank spaces to the right of the text), cheers.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
NBVC said:
Use the TRIM function to delete abnormal spaces.

=Trim(A1)

Is there any way you can use a command with trim to apply it to the whole worksheet, rather than recording a macro which adds a column with the trim, copying PasteSpecial-values, for each column, cheers.
 
Upvote 0
Yep that's perfect - many thanks for the link. Here is the code for anyone looking this up in a search:

Code:
Sub TrimCells()

Dim WorkRange As Range

Set WorkRange = Range("A1:I65536")

For Each Cell In WorkRange
    If Cell.Value = "" Then
        GoTo Next1
    Else
        Cell.Value = Trim(Cell.Value)
    End If
Next1:
Next Cell


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,249
Messages
6,177,423
Members
452,774
Latest member
Macca1962

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