Need a faster Code to delete Zeros

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hi there,

I am currently using the following code to delete zeros from a selection, however it is really slow. if there a different way of doing this?

Below is the code that I am currently using:

Code:
Sub Mytest()
Dim i As Integer
Dim Cnt0 As Integer
i = 0
Cnt0 = WorksheetFunction.CountIf(Selection, 0)
Cnt0 = Cnt0 + WorksheetFunction.CountIf(Selection, "<>" & 0)
Do
If ActiveCell.Value = 0 Then
ActiveCell.Value = ""
End If
ActiveCell.Offset(1, 0).Activate
i = i + 1
Loop Until i = Cnt0
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
Sub Mytest()
For Each cell In Selection
If cell.Value = "0" Then cell.Value = ""
Next cell
End Sub
 
Last edited:
Upvote 0
Try

Code:
    Selection.Replace What:="0", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

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
Back
Top