Replace greater then 0 macro

andonny

Board Regular
Joined
Mar 11, 2002
Messages
220
Hi,
I am looking for a macro to replace everything greater ten 0 in the range A1:D500.

I appreciater your help
andonny
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Sub removeZero()
    Application.ScreenUpdating = False
    With Range("A1:D500")
        For i = 1 To .Rows.Count
            For j = 1 To .Columns.Count
                With Range("A1:D500")(i, j)
                    If .Value > 0 Then
                        .Value = 0
                    End If
                End With
            Next j
        Next i
    End With
End Sub
Just replace the = 0 with = (what you want to put in the cells)
 
Upvote 0
In t(), I replace cells > 0 with 0. You can set it as you like.

Code:
Sub t()
  RangeFindReplace [A1:B500], ">", 0, 0
End Sub

Sub RangeFindReplace(theRange As Range, Operator As String, vFind As Variant, vReplace As Variant)
  Dim cell As Range
  For Each cell In theRange
    Select Case Operator
      Case Is = "="
        If cell.Value = vFind Then cell.Value = vReplace
      Case Is = ">="
        If cell.Value >= vFind Then cell.Value = vReplace
      Case Is = "<="
        If cell.Value <= vFind Then cell.Value = vReplace
      Case Is = ">"
        If cell.Value > vFind Then cell.Value = vReplace
      Case Is = "<"
        If cell.Value < vFind Then cell.Value = vReplace
    End Select
  Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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