Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Macro to replace "0" (Zero) with Hyphen in all Cells

I need a macro that will search each cell and determine if it has a zero
value in it. If it does, it will replace the zero (or in the case of my
data, 0.00), with a hyphen "-".

Here is an example:

Before

A B C D
1 Item1 $5.00 EACH 2.35
2 Item2 $0.75 EACH 0.50
3 Item3 $0.00 0.00
4 Item4 $2.50 CASE 0.00

After

A B C D
1 Item1 $5.00 EACH 2.35
2 Item2 $0.75 EACH 0.50
3 Item3 - -
4 Item4 $2.50 CASE -

As you can see, if a cell is blank and has no data in it, I don't want a
hyphen in there. Only where the cell has 0.00 in it. Thanks for the help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Macro to replace "0" (Zero) with Hyphen in all Cells

Hi KnightRider,

Try:

'=============
Public Sub Tester2()
Dim rng As Range

Set rng = Range("A1:A30") '<<==== CHANGE
rng.Replace What:="0", _
Replacement:="-", _
LookAt:=xlWhole, _
SearchOrder:=xlByRows
End Sub
'<<=============


---
Regards,
Norman



"KnightRiderAW" wrote in message
...
I need a macro that will search each cell and determine if it has a zero
value in it. If it does, it will replace the zero (or in the case of my
data, 0.00), with a hyphen "-".

Here is an example:

Before

A B C D
1 Item1 $5.00 EACH 2.35
2 Item2 $0.75 EACH 0.50
3 Item3 $0.00 0.00
4 Item4 $2.50 CASE 0.00

After

A B C D
1 Item1 $5.00 EACH 2.35
2 Item2 $0.75 EACH 0.50
3 Item3 - -
4 Item4 $2.50 CASE -

As you can see, if a cell is blank and has no data in it, I don't want a
hyphen in there. Only where the cell has 0.00 in it. Thanks for the
help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to replace "0" (Zero) with Hyphen in all Cells

for each cell in ActiveSheet.usedrange
if not isempty(cell) then
if cell.Value = 0 then
cell.Value = "-"
end if
end if
Next

--
Regards,
Tom Ogilvy

"KnightRiderAW" wrote in message
...
I need a macro that will search each cell and determine if it has a zero
value in it. If it does, it will replace the zero (or in the case of my
data, 0.00), with a hyphen "-".

Here is an example:

Before

A B C D
1 Item1 $5.00 EACH 2.35
2 Item2 $0.75 EACH 0.50
3 Item3 $0.00 0.00
4 Item4 $2.50 CASE 0.00

After

A B C D
1 Item1 $5.00 EACH 2.35
2 Item2 $0.75 EACH 0.50
3 Item3 - -
4 Item4 $2.50 CASE -

As you can see, if a cell is blank and has no data in it, I don't want a
hyphen in there. Only where the cell has 0.00 in it. Thanks for the

help!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to replace "0" (Zero) with Hyphen in all Cells

"KnightRiderAW" wrote in message
...
I need a macro that will search each cell and determine if it has a zero
value in it. If it does, it will replace the zero (or in the case of my
data, 0.00), with a hyphen "-".


Have you tried using the "Accounting" cell format? Does that suit your needs
or am I missing something?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Find" a wildcard as a place marker and "replace" with original va Eric Excel Discussion (Misc queries) 1 January 27th 09 06:00 PM
Macro to Replace/Delete Text Using "Watchword" List? PBJ Excel Discussion (Misc queries) 10 June 29th 07 09:50 PM
Replace dialog should put focus on "Find What" not "Replace With" Michael Williams Excel Discussion (Misc queries) 0 May 24th 06 12:45 PM
Macro causes "Do you want to replace the contents of the destination cells" JB[_2_] Excel Programming 1 October 16th 04 11:25 PM
within a macro how can I suppress the warning pop "A file named xxxx.xls already exists in this location. Do you want to replace it?" Pete McCosh Excel Programming 0 April 2nd 04 04:51 PM


All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"