Macro that will search in a column for a value equal or higher than 5

Piaba

New Member
Joined
Jan 31, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hello, I'm trying to create a macro that will search in a specific column for any number equal or above 5.

The trick here is that I want the macro to have each match selecting the whole row and make it stop. After I see the selected row, I would like to run the macro again and it will go for the next match and so on.

Mumps helped me with another macro that was doing similar, but in that case I was looking for specific keywords in a column. Here is the thread:


The macro that I did now loops through a specific column, but it doesnt stop at each match, so I think I cannot use a loop in this case. Tried a few end loop commands, but no lucky. Here is how the macro was looking like:

VBA Code:
Sub Depthcheck()

Dim rngSearch As Range
Dim LastRow As Long
Dim i As Integer

Application.ScreenUpdating = False
    
LastRow = Cells.Find("*", SearchOrder:=xlByRows, searchdirection:=xlPrevious).Row

Set rngSearch = Range("B" & Range("C2"))

For i = 4 To Range("B" & LastRow).End(xlUp).Row
    If Cells(i, "B").Value >= 5 Then
        Cells(i, "B").Activate
        Application.Goto ActiveCell.EntireRow, True
        Range("C2") = rngSearch.Row + 1
        Exit For
    End If
Next

Application.ScreenUpdating = True

End Sub

I had rngSearch as a helper cell to store the previous search. C2 always starts as "2".

I'm uploading an example of the structure of the file.
 

Attachments

  • Capture.PNG
    Capture.PNG
    7 KB · Views: 4

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hello, I'm trying to create a macro that will search in a specific column for any number equal or above 5.

The trick here is that I want the macro to have each match selecting the whole row and make it stop. After I see the selected row, I would like to run the macro again and it will go for the next match and so on.

Mumps helped me with another macro that was doing similar, but in that case I was looking for specific keywords in a column. Here is the thread:


The macro that I did now loops through a specific column, but it doesnt stop at each match, so I think I cannot use a loop in this case. Tried a few end loop commands, but no lucky. Here is how the macro was looking like:

VBA Code:
Sub Depthcheck()

Dim rngSearch As Range
Dim LastRow As Long
Dim i As Integer

Application.ScreenUpdating = False
   
LastRow = Cells.Find("*", SearchOrder:=xlByRows, searchdirection:=xlPrevious).Row

Set rngSearch = Range("B" & Range("C2"))

For i = 4 To Range("B" & LastRow).End(xlUp).Row
    If Cells(i, "B").Value >= 5 Then
        Cells(i, "B").Activate
        Application.Goto ActiveCell.EntireRow, True
        Range("C2") = rngSearch.Row + 1
        Exit For
    End If
Next

Application.ScreenUpdating = True

End Sub

I had rngSearch as a helper cell to store the previous search. C2 always starts as "2".

I'm uploading an example of the structure of the file.
It depends how long you want the code to pause for. If its just for you to note the row it stops on then you could try Application.Wait (Now + TimeValue("00:00:15")) which will pause the code for 15 seconds. Or just add a message box after it finds saying "Cell Found" the code then wont continue until you press ok
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,484
Members
448,967
Latest member
visheshkotha

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