change content in a cell

Schnet

New Member
Joined
Nov 30, 2005
Messages
8
I have a column with numbers in that format:
289-231-5274
but I need them without the "-"
How can I change that with the help of a macro?
Thanks
Schnet
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

just_jon

Legend
Joined
Sep 3, 2002
Messages
10,473
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> DashZapper()
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">With</SPAN> Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).SpecialCells(xlCellTypeConstants) <SPAN style="color:#007F00">'</SPAN>
    .Replace What:="-", Replacement:="", LookAt:=xlPart
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 

Schnet

New Member
Joined
Nov 30, 2005
Messages
8
Thank you very much!
Would you mind to explain me how that exactly works?
I worked with macros before but I'm still a beginner.
Schnet
 

just_jon

Legend
Joined
Sep 3, 2002
Messages
10,473
Schnet said:
Thank you very much!
Would you mind to explain me how that exactly works?
I worked with macros before but I'm still a beginner.
Schnet

The code simply calls Excel's native Replace function; the only thing "special" about it might be the designation of the range to search - it is limited to

a] column A only, and

b] only those cells having constant values - no formulas and ignore blanks, too.

Screen updating is turned off then back on because

a] you don't really need to see the screen flicker when it runs, but more importantly

b] it should run faster not having to update the screen but 1 time, when finished.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,632
Messages
5,832,774
Members
430,167
Latest member
Gogogoben

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