VBA code to pick data based on multiple conditions

tirumal

Board Regular
Joined
Feb 16, 2020
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Hello guys,



I've been struggling to write this for days macro and I have finally decided to ask for your help.


Here's what I have:



Sheet1 - Job IDs, Assignees and Tasks as headers



A1 - IDs

B1 - Assignees

C1 - Tasks

*Rest of the columns are something i've tried which did not work out.



There are different no. of Jobs in the data and each job has 2 tasks only. The tasks (task1 and task2) of each job are done by either 2 assignees separately or done by the same assignee (for some jobs).



What I am trying to achieve:



- I want to filter data in such a way that the macro should pick only five task1's and task2's of each assignee.

- But ideally, when a task2 of a job is picked, task 1 of the same job should also be picked keeping in mind that the assignee that did that task did not have more than 5 task1;s (or) task2's picked.

- My idea is, the macro should be able to ideally keep a log or delete data no. of tasks of a particular assignee once they reach the threshold of 5.

- To put it in simple terms, the no. of jobs picked do not matter, but both task 1 and 2 of any Job should be picked and each assignee should equally have 5 task1 and task2's.



I had multiple attempts but I have failed miserably. I would be really grateful if someone helps me out.

*Please find the file link here

Thank you,
Tirumal
 
JOB ID's
- your sample data is not your REAL data
- provide an true example of a REAL Job ID
- are all ID's of EQUAL length
- do all contain the same alpha characters at the beginning ?
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I am not prepared to download your file from that site
As requested in my first post plesae use XL2BB to post your sample data
 
Upvote 0
Ignore the previous one:
Posting only few rows of data here

Test.xlsx
ABC
1Job IDManagerDislike Option
2000064c8e46c47cb9979dcc0268f223dmmmadhrTRUE
3000064c8e46c47cb9979dcc0268f223dbjjoshFALSE
40002cfccbfb2485cb46ca73a465f76f6biswadmTRUE
50002cfccbfb2485cb46ca73a465f76f6rdnshFALSE
600110102441d4b478512d5e7691249ddsattiliTRUE
700110102441d4b478512d5e7691249ddsattiliFALSE
8001bce89bdba412a9120e6d86346509emtshahTRUE
9001bce89bdba412a9120e6d86346509esshakaFALSE
10001df3620e524224b4cd43d6575f8a63biswadmTRUE
11001df3620e524224b4cd43d6575f8a63elisatyFALSE
120025cfb502dc4ff1833ce4ee36855055agangeleTRUE
130025cfb502dc4ff1833ce4ee36855055wajakhanFALSE
14002646548b2e4428aa059dbacbc7dc92biswadmTRUE
15002646548b2e4428aa059dbacbc7dc92nikumarkFALSE
16002701827ff64d5a99c03e8794b481d1snghojTRUE
17002701827ff64d5a99c03e8794b481d1alfrdavFALSE
180029b3cdad244e6e9489f6cdcb4ccdd7snghojTRUE
190029b3cdad244e6e9489f6cdcb4ccdd7snghojFALSE
200029c74095cb4c5f848beb7bf158f630mtshahTRUE
210029c74095cb4c5f848beb7bf158f630skaveeshFALSE
220042544166e14942b4526401ba60dfcfrdnshTRUE
230042544166e14942b4526401ba60dfcfsiaditiFALSE
2400434abee4e84c2f9785d6da6e149211nkakullaTRUE
2500434abee4e84c2f9785d6da6e149211mmmadhrFALSE
2600494aee7a0a40e1b7c8ae4c376491c5vnchanTRUE
2700494aee7a0a40e1b7c8ae4c376491c5nkakullaFALSE
28004d143185fd4fceb8ef53eb9dca1384saithomTRUE
29004d143185fd4fceb8ef53eb9dca1384sattiliFALSE
3000544b4cc26f4a05995232dfeb9e5f63mnallanTRUE
Test
 
Upvote 0
I am shocked at how different that is from what you posted in your original workbook :eek:
(For the future) please be aware that posting rubbish sample data, that is not typical of your real data, is totally unhelpful to anyone trying to help you

Are TRUE & FALSE what you mean by Task1 and Task2 ?
 
Upvote 0
I thought that would make up for better understanding. Sorry for that. Learnt a lesson today.
Yes, True and false are the tasks.
 
Upvote 0
Ok - I think I now understand what you are struggling with

Must assign both TRUE and FALSE for any Job ID that is assigned
And
Each assignee must be assigned 5 X TRUE and 5 X FALSE

This is important:
Please confirm that column C always contains both TRUE and FALSE for every Job ID
 
Upvote 0
Yes, that is exactly what im trying to achieve.

True, column C always contains both TRUE and FALSE for every Job ID
 
Upvote 0
I need to test a few things
I will post suggestion tomorrow when back at my own PC
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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