Code to remove redundant spaces ?

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi

You can probably use the Trim worksheet function (although this will remove leading spaces too, and multiple instances of 'interior' spaces). Code-wise this could look like:

Code:
For Each cell In Intersect(Activecell.EntireColumn,Activesheet.UsedRange)
  If Not IsEmpty(cell) Then _
      cell.Value = RTrim(cell.Value)
Next cell

The above only removes trailing spaces.
 
Upvote 0
Hi

You can probably use the Trim worksheet function (although this will remove leading spaces too, and multiple instances of 'interior' spaces). Code-wise this could look like:

Code:
For Each cell In Intersect(Activecell.EntireColumn,Activesheet.UsedRange)
  If Not IsEmpty(cell) Then _
      cell.Value = RTrim(cell.Value)
Next cell

The above only removes trailing spaces.
 
Upvote 0
Hi

You can probably use the Trim worksheet function (although this will remove leading spaces too, and multiple instances of 'interior' spaces). Code-wise this could look like:

Code:
For Each cell In Intersect(Activecell.EntireColumn,Activesheet.UsedRange)
  If Not IsEmpty(cell) Then _
      cell.Value = RTrim(cell.Value)
Next cell

The above only removes trailing spaces.

Thanks - can you modify the code so that it can be applied to COL.D of Excel sheet ? Code is what i want as i only want to get rid off of trailing spaces.
 
Upvote 0
Sure:

Code:
For Each cell In Intersect(ActiveSheet.Range("D:D"),Activesheet.UsedRange)
  If Not IsEmpty(cell) Then _
      cell.Value = RTrim(cell.Value)
Next cell
 
Upvote 0
Sure:

Code:
For Each cell In Intersect(ActiveSheet.Range("D:D"),Activesheet.UsedRange)
  If Not IsEmpty(cell) Then _
      cell.Value = RTrim(cell.Value)
Next cell

Stupid qtn - where do i put the code ?
Right Click on worksheet> View Code & paste ?
 
Upvote 0
Somebody pls help with code.
i did ALT F11, insert module to paste the code & alt Q to close. Run compile. giving compilation error. Havr i gone wrong somewhere ?
 
Upvote 0
Does it give a description of teh error?
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

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