How to find and replace values greater than / less than a specific value in Excel?
Maybe, there are multiple data in your worksheet, now, you want to find all the cells which contain the value greater than or less than a specific number, and then replace them with another value you need at once. The normal Find and Replace feature is not applied to solve this problem, do you have any other good suggestions to deal with this task?
For example, I will find all the values which greater than 500, and replace them with 0.
The following VBA code can help you to replace the values which greater or less than a specific value at one, please do as follows:
1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Find and replace values greater or less than a specific value
Sub FindReplace() 'Updateby Extendoffice Dim Rng As Range Dim WorkRng As Range On Error Resume Next xTitleId = "KutoolsforExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) For Each Rng In WorkRng If Rng.Value > 500 Then Rng.Value = 0 End If Next End Sub
3. Then press F5 key to run this code, and select the range data that you want to replace from the prompt box, see screenshot:
4. And then click OK, and you can see all the values greater than 500 have been replaced with 0.
Note: In the above code, you can change the following variables to your desired.
- If Rng.Value > 500 Then
- Rng.Value = 0
If you are not familiar with the code, I can talk about a handy tool- Kutools for Excel, with its Select Specific Cells feature, you can quickly select the cells that you need, and then replace them at once.
|Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days.|
After installing Kutools for Excel, do as following steps:
1. Select the data range that you want to find and replace.
2. Click Kutools > Select > Select Specific Cells, see screenshot:
3. In the Select Specific Cells dialog box, click Cell option under Selection type, and choose Greater than from the Specific type drop down, and enter the value you want to use in the text box besides Greater than, see screenshot:
4. Then click OK button, all the cells greater than 500 have been selected immediately, then enter the value you need to replace with, and press Ctrl + Enter keys together, all the selected values have been replaced at the same time. See screenshots:
Note: In the Select Specific Cells dialog box, you can use other criteria, such as Less than, Equals, Contains, and so on.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
- To post as a guest, your comment is unpublished.· 1 years agoIf only there was a way to do the same without losing formulas(
- To post as a guest, your comment is unpublished.· 4 years agoIt's really awesome!!! I love it!