Macro to Trim all Columns that contain data in a Spreadsheet - Excel 2010

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello,


I have a sprreadsheet that is a direct download from SQL and it always places a blank character in front of some data in random columns. Is there a Macro that will look into all columns with Data and trim all cells so there is no spaces in front of data?

Hoping this is a easy one! Thanks guys!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi Johnny:

ON A COPY OF YOUR SPREADSHEET try this:

Code:
Sub Remove_Unwated_Spaces_From_Imported_Data()
' [URL]http://www.theexceladdict.com/nlarchive/120307tdg.htm#tip2[/URL]
    Cells.Select
    Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End Sub

I got this tip from Frances Hayes Excel Tips Newsletter. I just followed his steps and recorded the macro. If worse comes to worse maybe just follow his instructions manually. Here is a link to that:

http://www.theexceladdict.com/nlarchive/120307tdg.htm#tip2

Good Luck,
Mark
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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