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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Fr33dan

New Member
Joined
Jul 18, 2007
Messages
19
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

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,181
Office Version
  1. 365
Platform
  1. Windows
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,191,689
Messages
5,988,031
Members
440,124
Latest member
vincentchu2369

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