Pull data from sheet to new sheet based on multiple criteria from another sheet in excel

sallam Qasem

New Member
Joined
Dec 19, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hi Everyone.

I am seeking your assistance with a task involving two Excel sheets that I am currently working on.

The first sheet contains general household data, including a column that indicates the number of family members for each household. On the other hand, the second sheet contains detailed household member data. However, I am facing a challenge as the second sheet has more family members than the number specified in the first sheet.

I am in need VBA code that can help me extract member data to a new sheet based on the number of family members indicated in the first sheet. This would greatly streamline my workflow and ensure that I have accurate and organized data.

The below attached is the two sheets with few households and family members. But, kindly note that number of rows for both sheets I'm working for each file are hundreds thousands rows.

I would greatly appreciate any guidance, suggestions, or assistance you can provide in helping me achieve this task.


Household Information 3.xlsx
AB
1Household IDFamily Member
2368083833
3911085092
4231383824
5550183856
6945485095
7925985091
8479583743
9369383834
10902585094
11920485092
12930285094
13931185095
14902885097
15904185094
16905985092
17949385094
18967885092
19998885095
20547283856
21899285084
Sheet1





Household Information 3.xlsx
ABCD
1Household IDAgeGenderRecipient Type
24795837446FemaleRecipient 1
34795837445MaleRecipient 2
44795837482FemaleFamily Member
5479583745FemaleFamily Member
64795837442FemaleFamily Member
7479583749FemaleFamily Member
84795837410MaleFamily Member
92313838268MaleRecipient 1
102313838236MaleRecipient 2
11231383828FemaleFamily Member
12231383828MaleFamily Member
132313838263FemaleFamily Member
143680838328MaleRecipient 1
153680838329FemaleRecipient 2
16368083837FemaleFamily Member
173680838314MaleFamily Member
183680838314FemaleFamily Member
193680838367FemaleFamily Member
203693838342MaleRecipient 1
213693838339FemaleRecipient 2
223693838310MaleFamily Member
233693838313MaleFamily Member
243693838378MaleFamily Member
25369383833FemaleFamily Member
265472838562MaleRecipient 1
275472838559FemaleRecipient 2
285472838519FemaleFamily Member
295472838522FemaleFamily Member
305472838515FemaleFamily Member
315472838524FemaleFamily Member
325472838527FemaleFamily Member
335472838528MaleFamily Member
345501838550MaleRecipient 1
355501838546FemaleRecipient 2
365501838522FemaleFamily Member
375501838523FemaleFamily Member
385501838519MaleFamily Member
395501838518MaleFamily Member
40550183853MaleFamily Member
418992850844FemaleRecipient 1
428992850838MaleRecipient 2
438992850822FemaleFamily Member
448992850823FemaleFamily Member
458992850815MaleFamily Member
468992850824MaleFamily Member
478992850815FemaleFamily Member
489025850938FemaleRecipient 1
499025850948MaleRecipient 2
509025850915FemaleFamily Member
51902585098MaleFamily Member
52902585091FemaleFamily Member
53902585094FemaleFamily Member
549028850966MaleRecipient 1
559028850919MaleFamily Member
569028850915FemaleFamily Member
579028850922FemaleFamily Member
589028850917MaleFamily Member
599028850920FemaleFamily Member
609028850916MaleFamily Member
619028850949FemaleFamily Member
629041850946MaleRecipient 1
63904185099FemaleFamily Member
64904185097MaleFamily Member
65904185097MaleFamily Member
669041850933FemaleFamily Member
67904185091FemaleFamily Member
68904185091FemaleFamily Member
69904185093FemaleFamily Member
709059850982FemaleRecipient 1
719059850946MaleRecipient 2
72905985096MaleFamily Member
73905985095MaleFamily Member
749059850940FemaleFamily Member
759059850949FemaleFamily Member
76905985093MaleFamily Member
779110850937MaleRecipient 1
789110850927MaleRecipient 2
79911085096FemaleFamily Member
809110850928FemaleFamily Member
819204850956FemaleRecipient 1
829204850937MaleRecipient 2
839204850935FemaleFamily Member
849204850924FemaleFamily Member
859259850958MaleRecipient 1
869259850955FemaleRecipient 2
879259850921MaleFamily Member
889302850931MaleRecipient 1
899302850940MaleRecipient 2
909302850928FemaleFamily Member
919302850956FemaleFamily Member
92930285095FemaleFamily Member
93930285092MaleFamily Member
94930285096FemaleFamily Member
959302850922FemaleFamily Member
969311850934MaleRecipient 1
979311850958MaleRecipient 2
989311850923MaleFamily Member
999311850955FemaleFamily Member
1009311850926MaleFamily Member
1019311850930FemaleFamily Member
102931185095FemaleFamily Member
1039454850934MaleRecipient 1
1049454850935FemaleRecipient 2
105945485097FemaleFamily Member
1069454850911FemaleFamily Member
1079454850912MaleFamily Member
108945485093FemaleFamily Member
1099493850948MaleRecipient 1
1109493850916FemaleFamily Member
1119493850939FemaleFamily Member
1129493850912MaleFamily Member
113949385094FemaleFamily Member
1149678850961MaleRecipient 1
1159678850926MaleRecipient 2
1169678850919MaleFamily Member
1179678850931MaleFamily Member
1189678850923FemaleFamily Member
1199678850954FemaleFamily Member
1209988850945FemaleRecipient 1
1219988850912FemaleFamily Member
122998885097MaleFamily Member
1239988850916FemaleFamily Member
1249988850914FemaleFamily Member
1259988850951MaleFamily Member
Sheet2
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
What is the criteria for selecting the correct number of participants from the second table? How about showing us a mocked up solution based upon the data presented.
 
Upvote 0
The criteria is Family member column in Sheet1. Both sheets have household IDs. For example, the first household in Sheet 1 consists of 4 family members. However, in Sheet 2, you will find that this same household has 5 members per rows. My goal is to extract data for any 4 members from the same household based on Family member column in Sheet1 that indicates the number of family members and ignore the remaining 1 member, repeating this process for the other households.

The below is a sample data with mocked up solution.



Household Information 3.xlsx
BCDEFGHIJKLMNO
9
10Sheet1 "Household Data"Sheet2 "Family member Data"Sheet3 "Result"
11Household IDFamily MemberHousehold IDAgeGenderRecipient TypeHousehold IDAgeGenderRecipient Type
122313838242313838236MaleRecipient 22313838236MaleRecipient 2
133680838332313838268MaleRecipient 12313838268MaleRecipient 1
14550183856231383828FemaleFamily Member231383828FemaleFamily Member
15911085092231383828MaleFamily Member231383828MaleFamily Member
169454850952313838263FemaleFamily Member3680838329FemaleRecipient 2
173680838329FemaleRecipient 23680838328MaleRecipient 1
183680838328MaleRecipient 1368083837FemaleFamily Member
19368083837FemaleFamily Member5501838546FemaleRecipient 2
203680838314MaleFamily Member5501838550MaleRecipient 1
213680838314FemaleFamily Member5501838522FemaleFamily Member
223680838367FemaleFamily Member5501838523FemaleFamily Member
235501838546FemaleRecipient 25501838519MaleFamily Member
245501838550MaleRecipient 15501838518MaleFamily Member
255501838522FemaleFamily Member9110850927MaleRecipient 2
265501838523FemaleFamily Member9110850937MaleRecipient 1
275501838519MaleFamily Member9454850935FemaleRecipient 2
285501838518MaleFamily Member9454850934MaleRecipient 1
29550183853MaleFamily Member945485097FemaleFamily Member
309110850927MaleRecipient 29454850911FemaleFamily Member
319110850937MaleRecipient 19454850912MaleFamily Member
32911085096FemaleFamily Member
339110850928FemaleFamily Member
349454850935FemaleRecipient 2
359454850934MaleRecipient 1
36945485097FemaleFamily Member
379454850911FemaleFamily Member
389454850912MaleFamily Member
39945485093FemaleFamily Member
40
41
Sheet3
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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