Clear Contents

TexanJohn

New Member
Joined
Jun 13, 2017
Messages
12
I have a column of data with numeric values. Anything greater than 0 is valid, but how can I easily clear the contents of the cells with '0' as a value?

I have the same problem with a column of data with text. Anything with a value greater than "" is valid, but many cells have a value of "" (blank) that I want to clear. I have been trying different formulas, etc.

My reason for wanting to clear these values (either 0 in number column or blank in text column) is so that the finding the next valid value down the column works properly.

Any help is appreciated.

Thanks.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Sub ClearZeros()
With Sheets("Sheet1") ' Change to your sheet name
LR = .Cells(Rows.Count, "A").End(xlUp).Row 'Change "A" to whichever column
For i = LR To 2 Step -1 'Skips header row
If .Cells(i, "A").Value = 0 Then
.Cells(i, "A").Clear
End If
Next i
End With
End Sub
 
Upvote 0
Thanks for the suggestions.

I used something like this for clearing the 0's

Sub clrfrml()
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim c As Range
For Each c In Range("B2:B9527")
With c
If .Value = 0 Then .ClearContents
End With
Next c
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Code:
Sub delete_Zero()
    Columns("B:B").Replace What:="0", Replacement:="", LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
Way faster than looping through each range.
 
Upvote 0
Thanks for the suggestions.

I used something like this for clearing the 0's

Sub clrfrml()
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim c As Range
For Each c In Range("B2:B9527")
With c
If .Value = 0 Then .ClearContents
End With
Next c
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub


Sorry for the lack of code quotes, btw.

That works fine. A couple of things though:

1). I think my method will probably be slightly faster. You can certainly test that out and it may be negligible.
2). Make sure to incorporate some way to address the changing of shape in your data. My method will determine the last row and work until it's complete. Your method will require you to change the last row
Code:
("B2:B9527")
each time there is data added or removed from your dataset.

Good job!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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