random search with multiple conditions

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
161
Office Version
  1. 2016
Platform
  1. Windows
Hi

I am looking to do a random search on a sheet for auditing purposes. One issue is that the range of the search is not constant as new entries are done to the sheet weekly. I have two conditions: 1) the record must not have already been audited, 2) the result cannot return a blank

LevelProcess#CandidateBranchAudited
221-ICS-OE-HRSD-456John SmithOperationsYes
620-ICS-OI-HRSD-243Jane DoeOperationsNo
822-ICS-OE-HRSD-589Steve ParkerOperationsNo
723-ICS-OE-HRSD-247Ben WarrenOperationsYes

my present sheet has over 500 entries, but this is a small sample.

So, I need to press a button and a process# (from column B) appears in cell H4 on the same sheet but it cannot be a process that has already been audited (Yes)

Can someone help me with that?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
paste code into a module. run: FindProc
(you can put this macro btn on the Quick Access tool bar)
this assumes your last data column is F

Code:
Sub FindProc()
Dim lRows As Long
Dim vProcNum

On Error GoTo errFind
vProcNum = InputBox("Enter Proc#", "Find Proc#")
If vProcNum = "" Then Exit Sub

    Range("A1").Select
    ActiveSheet.UsedRange.Select
    lRows = ActiveSheet.UsedRange.Rows.Count
 
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$F$" & lRows).AutoFilter Field:=6, Criteria1:="No"
    Range("A1:F" & lRows).Select

    Selection.Find(What:=vProcNum, After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
 
    ActiveCell.Select
    MsgBox "Found"
Exit Sub
errFind:
Selection.AutoFilter
Range("A1").Select
MsgBox "[" & vProcNum & "] not found"
End Sub
 
Upvote 0
paste code into a module. run: FindProc
(you can put this macro btn on the Quick Access tool bar)
this assumes your last data column is F

Code:
Sub FindProc()
Dim lRows As Long
Dim vProcNum

On Error GoTo errFind
vProcNum = InputBox("Enter Proc#", "Find Proc#")
If vProcNum = "" Then Exit Sub

    Range("A1").Select
    ActiveSheet.UsedRange.Select
    lRows = ActiveSheet.UsedRange.Rows.Count
 
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$F$" & lRows).AutoFilter Field:=6, Criteria1:="No"
    Range("A1:F" & lRows).Select

    Selection.Find(What:=vProcNum, After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
 
    ActiveCell.Select
    MsgBox "Found"
Exit Sub
errFind:
Selection.AutoFilter
Range("A1").Select
MsgBox "[" & vProcNum & "] not found"
End Sub
thank you for the response...

I added the macro but got the following error message:

1694784291949.png

Also, the last column is AN which I made the required changes in the macro you gave me but not sure how this will populate a process# from column B into cell H4
 
Upvote 0
thank you for the response...

I added the macro but got the following error message:

View attachment 98776
Also, the last column is AN which I made the required changes in the macro you gave me but not sure how this will populate a process# from column B into cell H4
I believe that "xlFormulas2" only works in newer versions of Excel.
Older versions would have to use "xlFormulas", for the equivalent.
 
Upvote 0
hm
xlValues = -4163
so replace xValues with that number.

Selection.Find(What:=vProcNum, After:=ActiveCell, LookIn:=-4163 , _...
 
Upvote 0
now I get the following:

View attachment 98809
okay I get the following:
1694802953160.png


I may have not explained myself clearly ....

I require the search to extract a process number that already exists in column F. The purpose of the search is so that it gives me a process number that will need to be audited. The audit process must be at random as I cannot go in the list and pick one visually (for example, I can't just go to the next process that has "No" in column AN)

I hope this clarifies what I need, and I apologize if I wasn't clear.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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