Replace zero with nothing - ,acro

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
545
Office Version
  1. 365
Platform
  1. Windows
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 ..
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,761
Office Version
  1. 365
Platform
  1. Windows
Try

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

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
545
Office Version
  1. 365
Platform
  1. Windows
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
14,761
Office Version
  1. 365
Platform
  1. Windows
why not just use a formula?

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

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
545
Office Version
  1. 365
Platform
  1. Windows

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
14,761
Office Version
  1. 365
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

Well-known Member
Joined
Dec 15, 2009
Messages
545
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Thanks a lot for your advise - Ill try it
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
14,761
Office Version
  1. 365
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

Well-known Member
Joined
Dec 15, 2009
Messages
545
Office Version
  1. 365
Platform
  1. Windows
Thanks again :)
The problem seems to be solved
Have a nice weekend
 
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,700
Messages
5,833,213
Members
430,197
Latest member
edeibold

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