Removing Extra Spaces At The End Of Range Of Varying Cells

milwphil

Board Regular
Joined
Aug 1, 2010
Messages
120
Once again…… I’m stuck. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I’m trying to find a method of getting rid of unintentional extra space(s) at the end of range of cells (C11: Z –last row of data). I’ve found several discussions on how to use the Trim() function, but nothing that has worked for my situation. I think the problem I’m having is due to protected fields. <o:p></o:p>
<o:p></o:p>
My diagnosis is that the range is messed up (sorry for not being more technical than that). <o:p></o:p>
<o:p></o:p>
The other problem is that I need to have is that above the header row…I have a couple cells that need the same Trim() function (E5:E8).<o:p></o:p>
<o:p></o:p>
Any help someone could provide…would be GREATLY appreciated!<o:p></o:p>
<o:p></o:p>
Thanks,<o:p></o:p>
Phil <o:p></o:p>
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Once again…… I’m stuck. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I’m trying to find a method of getting rid of unintentional extra space(s) at the end of range of cells (C11: Z –last row of data). I’ve found several discussions on how to use the Trim() function, but nothing that has worked for my situation. I think the problem I’m having is due to protected fields. <o:p></o:p>
<o:p></o:p>
My diagnosis is that the range is messed up (sorry for not being more technical than that). <o:p></o:p>
<o:p></o:p>
The other problem is that I need to have is that above the header row…I have a couple cells that need the same Trim() function (E5:E8).<o:p></o:p>
<o:p></o:p>
Any help someone could provide…would be GREATLY appreciated!<o:p></o:p>
<o:p></o:p>
Thanks,<o:p></o:p>
Phil <o:p></o:p>
The macro at this website will remove all leading/trailing and multiple interspersed char 32 space characters. It will also remove and/or convert char 160 non breaking spaces into standard char 32 space characters. It will work on text or numbers and the numbers will be converted to true numeric numbers.

I use this macro dozens of times every single day! It's a real time saver.

http://www.mvps.org/dmcritchie/excel/join.htm#trimall
 
Upvote 0
Thanks for the link!

I see how to use the code in a basic form-as it is provided, but I need to have a defined range rather than a Selection. I'm not sure how to do that.

How can I manipulate the code to define the range. The problem I have is that the range will have a LastRow that may be different every time a user uses the file.

Sorry for being picky!
 
Upvote 0
This seems to work too, but I just can't figure out how to define my range...

Code:
Sub KillSupSpaces()
Dim rCell As Range
Dim strText As String
Dim lCount As Long        
 
With WorksheetFunction            
For Each rCell In Selection                
strText = rCell                
rCell = .Trim(.Clean(rCell))                 
If rCell <> strText Then lCount = lCount + 1            
Next rCell        
End With                        
MsgBox lCount & " cells had superfluous spacing"
 
End Sub
 
 


</PRE>
 
Upvote 0
Thanks for the link!

I see how to use the code in a basic form-as it is provided, but I need to have a defined range rather than a Selection. I'm not sure how to do that.

How can I manipulate the code to define the range. The problem I have is that the range will have a LastRow that may be different every time a user uses the file.

Sorry for being picky!
I'm not much of a programmer.

I'll bump this thread and maybe someone will see it and offer a better solution. Good luck! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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