Replace With Zero , but Keep existing Zeros

Russ At Index

Well-known Member
Joined
Sep 23, 2002
Messages
706
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Hello Excellers ,

Could someone shed some light on this little issue I have:

I have data b3 : h6

342 251 0 0 0 77 194
198 254 0 0 0 0 187
278 0 0 0 0 77 189
249 216 0 0 0 78 190

I would like to replace any cell value less than 100 with zero , at the same time keeping the
cells that are populated with zero.

Many thanks

Russ
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Here is some VBA code that will fix your whole range at once.
Code:
Sub ReplaceNums()

    Dim myRange As Range
    Dim cell As Range
    
'   ***SPECIFY RANGE TO APPLY TO***
    Set myRange = Range("B3:H6")
    
    Application.ScreenUpdating = False
    
'   Loop through all cells in range
    For Each cell In myRange
        If cell.Value > 0 And cell.Value < 100 Then
            cell.Value = 0
        End If
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Maybe...

Code:
Sub aTest()
    With Range("B3:H6")
        .Value = Evaluate(Replace("=IF(@<>0,IF(@<100,0,@),@)", "@", .Address))
    End With
End Sub

M.
 
Upvote 0
Heres a bit of code that should work but any formulas are gone:

Code:
Dim x As Variant

Set x = Range("B3:H6")
Range("B3:H6") = Evaluate("=IF(" & x.Address & "<100,0," & x.Address & ")")
 
Upvote 0

Forum statistics

Threads
1,216,071
Messages
6,128,623
Members
449,460
Latest member
jgharbawi

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