Suppose we have a list of scores, and we want to replace values equal and greater than 60 to text ‘PASS’, this work cannot be implemented by ‘Find and Replace’ function due to this function is only used for replacing a fixed value to another fixed value. Actually, we can edit VBA code to implement this special ‘Find and Replace’. Setting a fixed value in code, then after running macro, all values greater than this fixed value can be replaced with another value properly. This article will show you the details.

**Precondition:**

See screenshot below. We want to replace values >=60 with text ‘PASS’.

**Method: Find and Replace Values Greater Than or Less Than A Fixed Value by VBA Code**

**Step 1:** On current visible worksheet, **right click** on sheet name tab to load Sheet management menu. Select **View Code**, **Microsoft Visual Basic for Applications** window pops up.

Or you can enter **Microsoft Visual Basic for Applications** window via **Developer->Visual Basic**. You can also press **Alt + F11** keys simultaneously to open it.

**Step 2:** In **Microsoft Visual Basic for Applications** window, click **Insert->Module**, enter below code in Module1:

Sub FindAndReplace()
Dim UpdateRng As Range
Dim SelectRng As Range
Set SelectRng = Application.Selection
Set SelectRng = Application.InputBox("Select a Range", "Find and Replace", SelectRng.Address, Type:=8)
For Each UpdateRng In SelectRng
If UpdateRng.Value >= 60 Then
UpdateRng.Value = "PASS"
End If
Next
End Sub

**Step 3:** Save the macro and then quit **Microsoft Visual Basic for Applications**.

**Step 4:** Click **Developer->Macros** to run Macro.

You can also press **Alt+F8** to trigger **Macro **directly.

**Step 5:** Select ‘**FindAndReplace**’ and click **Run**.

**Step 6:** **FindAndReplace** dialog pops up. Enter **Select Range $B$2:$B$8**. In this step you can select the range you want to replace values.

**Step 7:** Click **OK**. Verify that values equal to or greater than 60 are replaced with ‘PASS’ properly.

**Comment:**

If you want to find and replace values less than a fixed value, just change below code:

For Each UpdateRng In SelectRng
If UpdateRng.Value >= 60 Then
UpdateRng.Value = "PASS"
End If
Next
To:
For Each UpdateRng In SelectRng
If UpdateRng.Value < 60 Then
UpdateRng.Value = "FAIL"
End If
Next

Related Posts

Calculate Number of Hours between Two Times
Calculating the difference between two times might be a valuable statistic for subsequent computations or averages, whether you're producing a time sheet for staff or recording personal exercises. While Excel has a plethora of complex functions, including date and time ...

Calculate Loan Interest in Given Year
When you borrow money, you are supposed to repay it gradually. Lenders, on the other hand, want to be compensated for their services and the risk they incur by lending you money. That is, you will not just repay the ...

Calculate Interest Rate for Loan
The interest rate is the fee charged by a lender to a borrower and is expressed as a percentage of the principal—the lent amount. The interest rate on a loan is often expressed as an annual percentage rate, abbreviated as ...

Calculate Interest for Given Period
Using the IPMT function in Excel, we can compute the interest payment on any loan. This step-by-step tutorial will guide Excel users of all skill levels through the process to calculate interest for given period. Finally, the formula: =IPMT(B3/12,1,B5,-B2) The ...

How To Use Excel GCD Function
This post will guide you how to use Excel GCD function with syntax and examples in Microsoft excel. Description The Excel GCD function Returns the greatest common divisor of two or more integers. So you can use the GCD function ...

Calculate A Ratio From Two Numbers In Excel
In elementary mathematics, a ratio is a connection or comparison between two or more integers. For example, ratios are often expressed as ":" to demonstrate the relationship between two numbers. You would think that manually calculating a ratio from two ...

How To Use Excel RRI Function
This post will guide you how to use Excel RRI function with syntax and examples in Microsoft excel. Description The Excel RRI function Returns an equivalent interest rate for the growth of an investment. So you can use the RRI ...

CAGR Formula Examples in Excel
CAGR in Excel is a formula that calculates the compound annual growth rate for any invested amount over the specified years or timeframe. Although there is no direct function in Excel that can help us identify the CAGR value, there ...

Build Hyperlink With VLOOKUP in Excel
You might have come across a task in which you were assigned to build hyperlinks, which seems very easy, and if you are new to excel or don't have enough experience with it, then you might wonder about doing this ...

Break ties with helper COUNTIF and column
Suppose you got a task to adjust the values that contain the ties; what would be your first attempt to break the ties of the given value? If you are wondering about doing this task manually, let me add that ...