Unique list based on Multiple Criteria VBA

xs4amit

New Member
Joined
May 21, 2018
Messages
34
Hi,

I am in need of a VBA code where it search a column based on multiple conditions (Check condition 1, if fails go to next condition.... and so on) in other columns and returns a unique list. Below is the table which explains it better:

NameEmp IDDateTask IDProduction countTask IDProduction CountTask IDProduction Count
AmitA162023/05ABC1200DEF1400GHI1100
PeterA144023/05DEF1450ABC1150GHI500
WilliamA129024/05GHI1500DEF1450JKL200

<tbody>
</tbody>


Now i need a list of Names who has worked on date 23/05 on task ABC in another sheet. Right now i am doing it with formula, but that is making the sheet too slow.

Thanks in advance
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Are the entries in the Date column real dates (Numbers) or Text?
 
Upvote 0
Further explaining, If i have 2 drop-downs list in next sheet like below, where red text is a drop down list. If i select the task and date, it should compare that to search the required result and display below it:


ABC23/May

<tbody>
</tbody>
 
Upvote 0
These are real dates (numbers)
In that case you could try this User-Defined Function. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

I have assumed that
- data is always laid out as you have shown with names in 1st column, date in 3rd, Task Id in 4th, 6th, etc
- a particular task ID will not occur more than once in the same row.
Code:
Function ListNames(rData As Range, dDate As Date, sTaskID As String, lNumInList As Long) As String
  Dim a As Variant, aNames As Variant
  Dim i As Long, j As Long
  Dim sNameList As String
  
  a = rData.Value
  For i = 1 To UBound(a, 1)
    If a(i, 3) = dDate Then
      For j = 4 To UBound(a, 2) Step 2
        If a(i, j) = sTaskID Then
          sNameList = sNameList & "|" & a(i, 1)
          Exit For
        End If
      Next j
    End If
  Next i
  aNames = Split(sNameList, "|")
  If lNumInList <= UBound(aNames) Then ListNames = aNames(lNumInList)
End Function

Excel Workbook
ABCDEFGHI
1NameEmp IDDateTask IDProduction countTask IDProduction CountTask IDProduction Count
2AmitA162023-MayABC1200DEF1400GHI1100
3PeterA144023-MayDEF1450ABC1150GHI500
4WilliamA129024-MayGHI1500DEF1450JKL200
Data




Formula in C2 is copied down

Excel Workbook
ABC
1Task IDDateNames
2ABC23-MayAmit
3Peter
4
Result
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,262
Members
449,075
Latest member
staticfluids

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