Macro to lowercase all letters and remove spaces

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
950
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I am looking for a macro to lowercase all letters and remove all spaces from the cells of a column, say column "B1:B500". Could anyone help with this?

thanking you in advance,
Andy
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try

Code:
Sub lc()
Dim c As Range
For Each c In Range("B1:B500")
    c.Value = Replace(c.Value, " ", "")
    c.Value = LCase(c.Value)
Next c
End Sub
 
Upvote 0
Try:

Code:
Sub neodjandre()

Dim iCell As Range

    For Each iCell In Selection
        iCell = LCase(Replace(iCell, " ", ""))
    Next iCell

End Sub

This is not set to a specific range, it will apply to whatever range you select on the sheet...
 
Last edited:
Upvote 0
Here's an alternative:

Code:
Sub Conv()
Dim r As Range
Set r = Range("B1:B500")
r.Value = Evaluate("IF(ROW(" & r.Address & "),LOWER(SUBSTITUTE(" & r.Address & ","" "","""")))")
End Sub
 
Upvote 0
Another one
Code:
Sub test()
Range("B1:B500").Value = [IF(ROW(b1:b500),LOWER(SUBSTITUTE(b1:b500," ","")))]
End Sub
 
Upvote 0
thanks guys! I will go for the simplest for the time being... but I am sure your other ideas will be useful in the future!
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

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