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
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,119,144
Messages
5,576,333
Members
412,717
Latest member
EVENTCATERING
Top