Search occurrences in a range, and if not found skip their procedure

APAL1

New Member
Joined
Jun 22, 2014
Messages
13
Hello all,

My code starts with a range that the code filters and there supposed to be left 3 values after filtering.
Each value has its own sub-procedure. The range is column "B".
I would like the first sub, the one that filters, to check if what is left after filtering is actually there.
If not, the sub will not call the routine that takes care of it, and will go to the next one.
At the same time, it should check if the 2nd value is there after filtering and if not - it will not call the routine that takes care of it and the same with the 3rd one..
My values are: 205,219,218. and the may appear more than once.
so occurrences may be: 205,219,218; 205,218; 205,219; 219,218.
Would someone have an idea how to deal with this?
Thanks a lot, this site is really helpful!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try this

Code:
Sub CheckValues()

    Dim rng As Range: Set rng = Range("B:B").SpecialCells(xlCellTypeVisible)
    
    If Not rng.Find(what:=205) Is Nothing Then Call Procedure205
    If Not rng.Find(what:=218) Is Nothing Then Call Procedure218
    If Not rng.Find(what:=219) Is Nothing Then Call Procedure219
    
End Sub

where Procedure205 etc is the name of a sub
 
Last edited:
Upvote 0
If there are multiple values in one cell you may need to use:

Code:
Sub CheckValues2()

    Dim rng As Range: Set rng = Range("B:B").SpecialCells(xlCellTypeVisible)
    
    If Not rng.Find(what:=205, lookat:=xlPart) Is Nothing Then Call Procedure205
    If Not rng.Find(what:=218, lookat:=xlPart) Is Nothing Then Call Procedure218
    If Not rng.Find(what:=219, lookat:=xlPart) Is Nothing Then Call Procedure219
    
End Sub
 
Upvote 0
and this looks to match the value of the cell as a whole

Code:
Sub CheckValues4()

    Dim rng As Range: Set rng = Range("B:B").SpecialCells(xlCellTypeVisible)
    
    If Not rng.Find(what:=205, lookat:=xlWhole) Is Nothing Then Call Procedure205
    If Not rng.Find(what:=218, lookat:=xlWhole) Is Nothing Then Call Procedure218
    If Not rng.Find(what:=219, lookat:=xlWhole) Is Nothing Then Call Procedure219
    
End Sub

Correct option to use depends on what the individual cells contain
Need to choose one that does not give false positives (eg 205 would be found within 2051 etc)
If you are struggling, please provide the values of a representative sample of "typical" filtered cells
- there are various methods avalable including MATCH, COUNTIF etc
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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