Macro to lowercase all letters and remove spaces

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
926
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
 

Some videos you may like

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"

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,808
Office Version
  1. 365
Platform
  1. Windows
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:

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707

ADVERTISEMENT

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
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Another one
Code:
Sub test()
Range("B1:B500").Value = [IF(ROW(b1:b500),LOWER(SUBSTITUTE(b1:b500," ","")))]
End Sub
 

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
926
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,509
Messages
5,596,568
Members
414,079
Latest member
Frills

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
Top