VBA query for Trim

RAMU

Active Member
Joined
Dec 11, 2009
Messages
321
Dear Friends,

I have a workbook with 4 sheets. Each sheet contains more than one lakh rows & minimum column From A to BR.

I wish to trim all cells of all sheets at a time. I got a VBA query from web which is not working properly:

Sub RemoveTrailingSpaces()
Dim Col As Range, combo As String
Application.ScreenUpdating = False
For Each Col In ActiveSheet.UsedRange.Columns
combo = Join(WorksheetFunction.Transpose(Col), Chr(1))
Do While InStr(combo, " " & Chr(1))
combo = Replace(combo, " " & Chr(1), Chr(1))
Loop
Col = WorksheetFunction.Transpose(Split(combo, Chr(1)))
Next
Application.ScreenUpdating = True
End Sub

After a certain row all cells are showing #N/A after running the above mentioned query.
I need help to get it done. Please help
Regards
RAMU
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about
VBA Code:
Sub Ramu()
   With ActiveSheet.UsedRange
      .Value = Evaluate("trim(" & .Address & ")")
   End With
End Sub
But with that amount of data it might take awhile
 
Upvote 0
How about
VBA Code:
Sub Ramu()
   With ActiveSheet.UsedRange
      .Value = Evaluate("trim(" & .Address & ")")
   End With
End Sub
But with that amount of data it might take awhile
Dear Sir,
First of all can't get Sub Ramu()
Second I wish to trim all the cells of all sheets at a time. Will it work ?
Regards
RAMU
 
Upvote 0
Please explain what you mean by "First of all can't get Sub Ramu() "
 
Upvote 0
Just copy the code using the copy button at the top right of the code window
1583175762540.png

and then paste it into a standard module
 
Upvote 0
If you can't copy/paste it, then you will need to type it out. Just make sure you do it exactly as written.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,568
Messages
6,125,599
Members
449,238
Latest member
wcbyers

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