Multiple criteria

adambc

Active Member
Joined
Jan 13, 2020
Messages
412
Office Version
  1. 365
Platform
  1. Windows
I have a WB with 3 columns ...

CustomerID - one or many records depending on number of ServiceType

ServiceType - 10 possible values

ServiceEndDate

- I'm only interested in 4 of the 10 ServiceType values (let's call them A, B, C & D)
- I want to copy EVERY record for the CustomerID to another WS irrespective of ServiceType/ServiceEndDate
- IF all records with ServiceType A, B, C or D also have a ServiceEndDate (if ANY record has a ServiceType of A, B, C or D but DOES NOT have a ServiceEndDate then I don't want to do anything)

Is this possible?

Thanks ...
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I think you can do what you want using the new FILTER function.

Here is an example:
1730311744428.png


On the left is the data set, and on the right in red is the data you want returned.
The formula I used in cell F2 is this:
Excel Formula:
=FILTER(A2:C26,((B2:B26="A")+(B2:B26="B")+(B2:B26="C")+(B2:B26="D"))*(C2:C26>0))
 
Upvote 0
I think you can do what you want using the new FILTER function.

Here is an example:
View attachment 118753

On the left is the data set, and on the right in red is the data you want returned.
The formula I used in cell F2 is this:
Excel Formula:
=FILTER(A2:C26,((B2:B26="A")+(B2:B26="B")+(B2:B26="C")+(B2:B26="D"))*(C2:C26>0))
Thanks ...

Two gotchas!

1. I need to do this in a macro (VBA)
2. CustomerID can have multiple ServiceType ie multiple records

But I will look at FILTER later ...
 
Upvote 0
1. I need to do this in a macro (VBA)
OK, you didn't mention this in your original request, but I have to ask why it has to be VBA?
Note that you can use VBA to enter in this formula.

2. CustomerID can have multiple ServiceType ie multiple records
I don't see why that should be any issue, unless there is something else related to this you aren't telling us.
The FILTER function simply returns any record that uses one of those 4 ServiceTypes and has a ServiceEndDate.
 
Upvote 0
OK, you didn't mention this in your original request, but I have to ask why it has to be VBA?
Note that you can use VBA to enter in this formula.


I don't see why that should be any issue, unless there is something else related to this you aren't telling us.
The FILTER function simply returns any record that uses one of those 4 ServiceTypes and has a ServiceEndDate.
It’s a section in the middle of a longer macro - should have said in my post, but yes, I can use VBA to insert the FILTER formula …

But … I’d already got there with VBA - the piece it doesn’t handle (?) is checking ALL instances are satisfied - if any fail I need to exclude that CustomerID completely - but I think I’ve cracked it now by checking for a FALSE before doing anything else
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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