vba code to check if there is a name in a column and check that column for a desired char

MrRed

New Member
Joined
Apr 20, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Good day everyone,
I'm quite new to the site but known it for a while.
I would like to ask for your help in automating an excel file to perform a task.
In particular, I have a table where in the first column theres a list on names and across there is a list of abilitations.
The table is filled with "x" where the person has that particular abilitation.
I would like to input a persons name and have returned the list of obtained abilitations, like in the picture attached, without the spaces.
Additionally each abilitation has a responsable, it would be nice to have their names printed next to the corresponding abilitation.
Hope I managed to explain myself decently.
Thank you in advance for any kind of help.
 

Attachments

  • image1.jpg
    image1.jpg
    195.7 KB · Views: 30

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
You have three tables shown in your example. Which one is it that you are trying to populate?
It might be more helpful to show us a BEFORE image (of what you have to start) and then your desired result.

Also, it would be much more helpful if you posted your data in a way which we can copy it do our side (which we cannot do with images).
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Thank you for replying so quickly.
The following is the table where the data is inserted.

project2.xlsm
CDEFGHIJKLM
4nome\abilitazioneabilitazione 1abilitazione 2abilitazione 3abilitazione 4abilitazione 5abilitazione 6abilitazione 7abilitazione 8abilitazione 9abilitazione 10
5lavoratore 1xxxxx
6lavoratore 2xxxxxx
7lavoratore 3xxxx
Foglio1



Under the C column there are the names of workers and in row 4 the possible abilitations each worker can have. By filling an "x" in the table each worker is assigned one or more abilitations.
I would like to have a macro that takes a workers name as input, finds the name in the C column, checks how many x there are in the matching row and returns the name of that abilitation/s as follows (the formulas that are present at the moment are an attempt to make this work without macros, but if I were to update the workers list or add more abilitations in the future I would pretty much have to change all of the formulas in all of the cells which isn't realy desirable)

project2.xlsm
ABCD
9search workerlavoratore 1
10corsoresponsabile
11abilitazione 1Mario
12 0
13abilitazione 3Pino
14 0
15abilitazione 5Rino
16 0
17abilitazione 7Cino
18 0
19abilitazione 9Pino
20 0
Foglio1
Cell Formulas
RangeFormula
C11C11=IFERROR(IF($C$9=$C$5,INDEX($D$4,MATCH("x",$D$5,0)),IF($C$9=$C$6,INDEX($D$4,MATCH("x",$D$6,0)),IF($C$9=$C$7,INDEX($D$4,MATCH("x",$D$7,0))))),"")
D11D11=IF($C$11=Foglio3!$C$4,Foglio3!$D$4,IF($C$11=Foglio3!$C$5,Foglio3!$D$5,IF($C$11=Foglio3!$C$6,Foglio3!$D$6,IF(Foglio1!$C$11=Foglio3!$C$7,Foglio3!$D$7,IF(Foglio1!$C$11=Foglio3!$C$8,Foglio3!$D$8,IF(Foglio1!$C$11=Foglio3!$C$9,Foglio3!$D$9,IF(Foglio1!$C$11=Foglio3!$C$10,Foglio3!$D$10,IF(Foglio1!$C$11=Foglio3!$C$11,Foglio3!$D$11,IF(Foglio1!$C$11=Foglio3!$C$12,Foglio3!$D$12,IF(Foglio1!$C$11=Foglio3!$C$13,Foglio3!$D$13,""))))))))))
C12C12=IFERROR(IF($C$9=$C$5,INDEX($E$4,MATCH("x",$E$5,0)),IF($C$9=$C$6,INDEX($E$4,MATCH("x",$E$6,0)),IF($C$9=$C$7,INDEX($E$4,MATCH("x",$E$7,0))))),"")
D12:D16D12=IF(C12=Foglio3!C5,Foglio3!D5,IF(C12=Foglio3!C6,Foglio3!D6,IF(C12=Foglio3!C7,Foglio3!D7,IF(Foglio1!C12=Foglio3!C8,Foglio3!D8,IF(Foglio1!C12=Foglio3!C9,Foglio3!D9,IF(Foglio1!C12=Foglio3!C10,Foglio3!D10,IF(Foglio1!C12=Foglio3!C11,Foglio3!D11,IF(Foglio1!C12=Foglio3!C12,Foglio3!D12,IF(Foglio1!C12=Foglio3!C13,Foglio3!D13,IF(Foglio1!C12=Foglio3!C14,Foglio3!D14,""))))))))))
C13C13=IFERROR(IF($C$9=$C$5,INDEX($F$4,MATCH("x",$F$5,0)),IF($C$9=$C$6,INDEX($F$4,MATCH("x",$F$6,0)),IF($C$9=$C$7,INDEX($F$4,MATCH("x",$F$7,0))))),"")
C14C14=IFERROR(IF($C$9=$C$5,INDEX($G$4,MATCH("x",$G$5,0)),IF($C$9=$C$6,INDEX($G$4,MATCH("x",$G$6,0)),IF($C$9=$C$7,INDEX($G$4,MATCH("x",$G$7,0))))),"")
C15C15=IFERROR(IF($C$9=$C$5,INDEX($H$4,MATCH("x",$H$5,0)),IF($C$9=$C$6,INDEX($H$4,MATCH("x",$H$6,0)),IF($C$9=$C$7,INDEX($H$4,MATCH("x",$H$7,0))))),"")
C16C16=IFERROR(IF($C$9=$C$5,INDEX($I$4,MATCH("x",$I$5,0)),IF($C$9=$C$6,INDEX($I$4,MATCH("x",$I$6,0)),IF($C$9=$C$7,INDEX($I$4,MATCH("x",$I$7,0))))),"")
C17C17=IFERROR(IF($C$9=$C$5,INDEX($J$4,MATCH("x",J5,0)),IF($C$9=$C$6,INDEX($J$4,MATCH("x",J6,0)),IF($C$9=$C$7,INDEX($J$4,MATCH("x",$J$7,0))))),"")
D17:D20D17=IF(C17=Foglio3!C10,Foglio3!D10,IF(C17=Foglio3!C11,Foglio3!D11,IF(C17=Foglio3!C12,Foglio3!D12,IF(Foglio1!C17=Foglio3!C13,Foglio3!D13,IF(Foglio1!C17=Foglio3!C14,Foglio3!D14,IF(Foglio1!C17=Foglio3!C15,Foglio3!D15,IF(Foglio1!C17=Foglio3!C16,Foglio3!D16,IF(Foglio1!C17=Foglio3!C17,Foglio3!D17,IF(Foglio1!C17=Foglio3!C18,Foglio3!D18,IF(Foglio1!C17=Foglio3!C19,Foglio3!D19,FALSE))))))))))
C18C18=IFERROR(IF($C$9=$C$5,INDEX($K$4,MATCH("x",K5,0)),IF($C$9=$C$6,INDEX($K$4,MATCH("x",K6,0)),IF($C$9=$C$7,INDEX($K$4,MATCH("x",$K$7,0))))),"")
C19C19=IFERROR(IF($C$9=$C$5,INDEX($L$4,MATCH("x",L5,0)),IF($C$9=$C$6,INDEX($L$4,MATCH("x",L6,0)),IF($C$9=$C$7,INDEX($L$4,MATCH("x",$L$7,0))))),"")
C20C20=IFERROR(IF($C$9=$C$5,INDEX($M$4,MATCH("x",M5,0)),IF($C$9=$C$6,INDEX($M$4,MATCH("x",M6,0)),IF($C$9=$C$7,INDEX($M$4,MATCH("x",$M$7,0))))),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D11:D20Cell Value=0textNO
Cells with Data Validation
CellAllowCriteria
C9List=$C$5:$C$7


I would like it not to have blanks where an abilitations is not aquired by the worker.

Lastly, each abilitation is managed by a supervisor whos name should show up next to the corresponding abilitation as shown above. The following is the data for supervisors.

project2.xlsm
CD
3abilitazioneresponsabile
4abilitazione 1Mario
5abilitazione 2Gino
6abilitazione 3Pino
7abilitazione 4Lino
8abilitazione 5Rino
9abilitazione 6Bino
10abilitazione 7Cino
11abilitazione 8GIno
12abilitazione 9Pino
13abilitazione 10Lino
Foglio3


Thank you for any kind of help.

Let me know if I have to add more info.
 
Upvote 0
You can do that without a macro if you interested.
+Fluff 1.xlsm
ABCDEFGHIJKLM
1
2
3
4nome\abilitazioneabilitazione 1abilitazione 2abilitazione 3abilitazione 4abilitazione 5abilitazione 6abilitazione 7abilitazione 8abilitazione 9abilitazione 10
5lavoratore 1xxxxx
6lavoratore 2xxxxxx
7lavoratore 3xxxx
8
9search workerlavoratore 1
10corsoresponsabile
11abilitazione 1Mario
12abilitazione 3Pino
13abilitazione 5Rino
14abilitazione 7Cino
15abilitazione 9Pino
16  
17  
18  
19  
20
21
22
Main
Cell Formulas
RangeFormula
C11:C19C11=IFERROR(INDEX($D$4:$M$4,AGGREGATE(15,6,(COLUMN($D$4:$M$4)-COLUMN($D$4)+1)/($C$5:$C$7=$C$9)/($D$5:$M$7="x"),ROWS(C$11:C11))),"")
D11:D19D11=IF(C11="","",VLOOKUP(C11,Foglio3!C3:D13,2,0))
Cells with Data Validation
CellAllowCriteria
C9List=$C$5:$C$7
 
Upvote 0
Solution
It works like a charm you absolute leggend. Thank you so much.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,124
Members
453,021
Latest member
Justyna P

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