Replace zero with nothing - ,acro

blaksnm

Active Member
Joined
Dec 15, 2009
Messages
498
Hey Guys
I try to record a macro that replace all single-zeros (just the cells where one zero-character is the whole input) with blanc (I want to emty all cells that contain this singel zero-character.

I know i have seen something like this before, but dont remember where ..
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,808
Office Version
  1. 2019
Platform
  1. Windows
Try

Code:
Sub test()
Cells.Replace What:="0", Replacement:="", LookAt:=xlWhole
End Sub
 

blaksnm

Active Member
Joined
Dec 15, 2009
Messages
498
Thanks - that macro works ... in a way ...
I use the tecnique to count cells containing something else than zero (skip counting blanks) on a range.
Your macro replaces zero with blanc all right, but still - when i use the count-formulas on the range - the cells seems to contain some hidden characters ore something that make my formula respond with a count. This is only correctet when I use the delete-button on the appearently emty cell.
Are there a way around this problem?
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,808
Office Version
  1. 2019
Platform
  1. Windows
why not just use a formula?

=countif(A1:Z99,"<>0")-countblank(A1:Z99)
 

blaksnm

Active Member
Joined
Dec 15, 2009
Messages
498

ADVERTISEMENT

Good sugestion, but as long as the "empty" cells value is som kind of hidden value the formula wil not read this as blank
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,808
Office Version
  1. 2019
Platform
  1. Windows
I meant use the formula without clearing the 0 values first.

=countif(A1:Z99,"<>0") will count all cells that have anything other than 0 (which will include empty cells if there are any)

then -countblank(A1:Z99) will subtract the count of empty cells (if any) to give a true count of non 0 values.<!-- / message -->
 

blaksnm

Active Member
Joined
Dec 15, 2009
Messages
498

ADVERTISEMENT

Thanks a lot for your advise - Ill try it
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
10,808
Office Version
  1. 2019
Platform
  1. Windows
I have a way of doing what you asked originally, but the macro recorder doesn't recognise what is being done, and so far no luck in finding any way to code it, to do it manually.

Ctrl F

Find What : 0

Options >> Match entire cell contents -- yes

Find All

Ctrl A

Escape

Delete
 

blaksnm

Active Member
Joined
Dec 15, 2009
Messages
498
Thanks again :)
The problem seems to be solved
Have a nice weekend
 

Watch MrExcel Video

Forum statistics

Threads
1,108,492
Messages
5,523,260
Members
409,506
Latest member
reneekeane

This Week's Hot Topics

Top