Trim function

SimonHughes

Well-known Member
Joined
Sep 16, 2009
Messages
507
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am using Excel 2010

Is it possible to use the trim function in cell? I want to change what we see in A1 to what we see in A2 without using insert column > copy > paste special etc. Your help appreciated

<TABLE style="WIDTH: 71pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=94><COLGROUP><COL style="WIDTH: 23pt; mso-width-source: userset; mso-width-alt: 1097" width=30><COL style="WIDTH: 48pt" width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 23pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=17 width=30></TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 width=64>A</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 23pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=17 width=30 align=right>1</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl67 width=64>. Mydata</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 23pt; HEIGHT: 12.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=17 width=30 align=right>2</TD><TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl67 width=64>Mydata</TD></TR></TBODY></TABLE>
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You can use it in cell but it depends on the use...

If you will use the function in A1 you should put the result of that function in different cell rather than A1 otherwise there will be error.

Trim function check in Excel Help...
It trims more than 1 spaces in your data even you apply trim nothing will happen since only 1 space is there..
 
Upvote 0
Many thanks but I still do not know how to trim in the active cell - can you help on that?
 
Upvote 0
You can do what you want to do with the substitute function:

=SUBSTITUTE(SUBSTITUTE(A1," ",""),".","")
 
Upvote 0
That's correct - I need the solution to be done in the active cell
 
Upvote 0
You need a macro for that. Very simple one that works on the cell that's currently selected:
Code:
Sub ReplaceSpaces()
    ActiveCell.Replace What:=".", Replacement:=""
    ActiveCell.Replace What:=" ", Replacement:=""
End Sub
 
Upvote 0
To trim a cell in situ you will need a macro

Code:
Sub ATrim()
With ActiveCell
    .Value = Trim(.Value)
End With
End Sub
 
Upvote 0
Thats great, both work well, many thanks. However, can these macro's be adapted to work on a range of cells?
 
Upvote 0
Try

Code:
Sub ATrim()
Dim c As Range
For Each c In Selection
    c.Value = Trim(c.Value)
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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