Returning values if cells in array contain specific text

keiranwyllie

New Member
Joined
May 12, 2017
Messages
47
G'Day everyone,

I hope I can explain this one well enough because I haven't found any helpful hints/clues as yet.

I have a training spreadsheet with two worksheets. One sheet is a matrix (Matrix worksheet.png) of courses/course descriptions and employed positions. There's an area on that sheet to assign training as either Essential or Desirable, represented by an 'E' or 'D' respectively. This is just a basic sheet.

The second sheet (Training Captured.png) is intended to then capture the training identified as 'E' or 'D' and transpose the employed position and course description data automatically, based on where the 'Es' and 'Ds' are.

I feel this could get out of hand very easily because as 'Es' and 'Ds' are changed, there's potential for blank rows. I see this can all be solved with vba but I'm kind of lost as to where to start.

Caveat - my current version of this spreadsheet can handle this manually meaning I look at the matrix, then go to the other sheet and manually add the data. I was just hoping I might be able to do this automatically.

Any help will be greatly appreciated.
 

Attachments

  • Matrix worksheet.PNG
    Matrix worksheet.PNG
    29.9 KB · Views: 22
  • Training Captured.PNG
    Training Captured.PNG
    18.6 KB · Views: 21

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Keiranwyllie is there any way you could use that XLB up load? It would make helping you out much easier.

Posting Data use XL2BB version1.2.8 (8th Aug 2020)
 
Upvote 0
Alrighty, I'll give this one a go.

Analysis Doc.xlsm
ABCDEFGHIJ
3PositionDesignationPosition NumberActivity Alignment or Business NeedCourse TitleDescriptionTraining CompleteAvailabilityProvided by (Organisation)Development or Training Req'd
4
5
6
7
8
9
10
11DO NOT ADD NEW ROWS BELOWDO NOT ADD NEW ROWS BELOWDO NOT ADD NEW ROWS BELOW
Training & Gap Analysis


Analysis Doc.xlsm
ABCDEFGHIJKLMNO
2Course / PositionPosition 1Position 2Position 3Position 4Position 5Position 6Position 7Position 8Position 9Position 10Position 11Position 12
3TrainingEssential/Desireable or otherwise trainedDescription
4Course 1EEEEEECourse description 1
5Course 2EDDEECourse description 2
6Course 3DDDDCourse description 3
7Course 4DDEEEEECourse description 4
8Course 5EEDEDEECourse description 5
9DO NOT INSERT ROWS BELOW
Matrix
 
Upvote 0
Can you give us an example of the output or what you want to see when everything is completed.
 
Upvote 0
Sure. Looking at the Matrix above, we see that each position has allocated training. What I'm aiming for is that when a "E" or "D" is entered in the Matrix, it'll autopopulate the other worksheet by looking up the corresponding Position, Course and Course descriptions and fill into columns A, E and F respectively as shown below.

I feel it'll have to be done in a Worksheet_Change function but not really sure where to start.

I think that once I have the start, I'll be able to incorporate changes such as an "E" or "D" changes against a position so I can update that row instead of adding to a new row while retaining old information.

Analysis Doc.xlsm
ABCDEFGHIJ
3PositionDesignationPosition NumberActivity Alignment or Business NeedCourse TitleDescriptionTraining CompleteAvailabilityProvided by (Organisation)Development or Training Req'd
4Position 1Course 1Course description 1
5Position 1Course 4Course description 4
6Position 1Course 5Course description 5
7Position 2Course 2Course description 2
8Position 2Course 4Course description 4
9Position 2Course 5Course description 5
10
11DO NOT ADD NEW ROWS BELOWDO NOT ADD NEW ROWS BELOWDO NOT ADD NEW ROWS BELOW
Training & Gap Analysis
 
Upvote 0
All are ARRAY formulas to be copied down. If you drag further down after 9th row you will get data of all positions upto Position 12.
In A3
=IFERROR(INDEX(Sheet1!$B$2:$M$2,SMALL(IF(COUNTIF(OFFSET(Sheet1!$B$4:$B$8,0,0,,COLUMN(Sheet1!$B$2:$M$2)-COLUMN(Sheet1!$B$2)+1),"=?*")>=ROWS($A$3:$A3),COLUMN(Sheet1!$B$2:$M$2)-COLUMN(Sheet1!$B$2)+1,""),1)),"")

In E3
=IFERROR(INDEX(Sheet1!$A$4:$A$8,SMALL(IF(INDEX(Sheet1!$B$4:$M$8,,MATCH($A3,Sheet1!$B$2:$M$2,0))<>"",ROW(Sheet1!$A$4:$A$8),""),COUNTIF($A$3:$A3,$A3))-ROW(Sheet1!$A$4)+1),"")

In F3
=IFERROR(INDEX(Sheet1!$O$4:$O$8,SMALL(IF(INDEX(Sheet1!$B$4:$M$8,,MATCH($A3,Sheet1!$B$2:$M$2,0))<>"",ROW(Sheet1!$A$4:$A$8),""),COUNTIF($A$3:$A3,$A3))-ROW(Sheet1!$A$4)+1),"")

ARRAY formula is used

To enter ARRAY formula
Paste the formula
Press F2
Press Ctrl+Shift+Enter keys together.
formula will be covered with{} brackets by excel.
 
Upvote 0
Because you can never have too many VBA answers here is mine. keiranwyllie now I don't know how much you know about excel and vba so if you have questions please ask. Now I took some liberties with your form. You will notice that you can only get one position at a time. If this is a problem let me know. But the ability to select a position from a drop down list, should make things go a little faster. If you do have more questions then answers, let us know.



VBA Code:
Sub Train1()
Dim Row1 As Long
Dim Row2 As Long
Dim Col1 As Long

 Range("A3:F8").Select
    Selection.ClearContents
    Range("A3").Select
    
For Col1 = 1 To 12
If Sheets("Traniing & Gap Analysis").Range("A2") = "Position " & Col1 Then

Exit For
End If

Next Col1

Col1 = Col1 + 1

Row2 = 3

For Row1 = 3 To 7

If Sheets("Matrix").Cells(Row1, Col1) = "E" Or Sheets("Matrix").Cells(Row1, Col1) = "D" Then
Debug.Print Sheets("Matrix").Cells(Row1, 2)
Sheets("Traniing & Gap Analysis").Cells(Row2, 1) = Sheets("Traniing & Gap Analysis").Range("A2")
Sheets("Traniing & Gap Analysis").Cells(Row2, 5) = Sheets("Matrix").Cells(Row1, 1)
Sheets("Traniing & Gap Analysis").Cells(Row2, 6) = Sheets("Matrix").Cells(Row1, 15)

Row2 = Row2 + 1

End If

Next Row1

End Sub


20-09-20 Train.xlsm
ABCDEFGHIJKL
1PositionDesignationPosition NumberActivity Alignment or Business NeedCourse TitleDescriptionTraining CompleteAvailabilityProvided by (Organisation)Development or Training Req'd
2Position 7Position 1
3Position 7Course 3Course description 3Position 2
4Position 7Course 5Course description 5Position 3
5Position 4
6Position 5
7Position 6
8Position 7
9DO NOT ADD NEW ROWS BELOWDO NOT ADD NEW ROWS BELOWDO NOT ADD NEW ROWS BELOWPosition 8
10Position 9
11Position 1Course 1Course description 1
12Position 1Course 4Course description 4
13Position 1Course 5Course description 5
14Position 2Course 2Course description 2
15Position 2Course 4Course description 4
16Position 2Course 5Course description 5
Traniing & Gap Analysis
Cells with Data Validation
CellAllowCriteria
A2List=$L$2:$L$10


20-09-20 Train.xlsm
ABCDEFGHIJKLMNO
1Course / PositionPosition 1Position 2Position 3Position 4Position 5Position 6Position 7Position 8Position 9Position 10Position 11Position 12
2TrainingEssential/Desireable or otherwise trainedDescription
3Course 1EEEEEECourse description 1
4Course 2EDDEECourse description 2
5Course 3DDDDCourse description 3
6Course 4DDEEEEECourse description 4
7Course 5EEDEDEECourse description 5
8DO NOT INSERT ROWS BELOW
Matrix
 
Upvote 0
All are ARRAY formulas to be copied down. If you drag further down after 9th row you will get data of all positions upto Position 12.
In A3
=IFERROR(INDEX(Sheet1!$B$2:$M$2,SMALL(IF(COUNTIF(OFFSET(Sheet1!$B$4:$B$8,0,0,,COLUMN(Sheet1!$B$2:$M$2)-COLUMN(Sheet1!$B$2)+1),"=?*")>=ROWS($A$3:$A3),COLUMN(Sheet1!$B$2:$M$2)-COLUMN(Sheet1!$B$2)+1,""),1)),"")

In E3
=IFERROR(INDEX(Sheet1!$A$4:$A$8,SMALL(IF(INDEX(Sheet1!$B$4:$M$8,,MATCH($A3,Sheet1!$B$2:$M$2,0))<>"",ROW(Sheet1!$A$4:$A$8),""),COUNTIF($A$3:$A3,$A3))-ROW(Sheet1!$A$4)+1),"")

In F3
=IFERROR(INDEX(Sheet1!$O$4:$O$8,SMALL(IF(INDEX(Sheet1!$B$4:$M$8,,MATCH($A3,Sheet1!$B$2:$M$2,0))<>"",ROW(Sheet1!$A$4:$A$8),""),COUNTIF($A$3:$A3,$A3))-ROW(Sheet1!$A$4)+1),"")

ARRAY formula is used

To enter ARRAY formula
Paste the formula
Press F2
Press Ctrl+Shift+Enter keys together.
formula will be covered with{} brackets by excel.

I gave this a go and it works well for columns A, E & F. The downside is that if an "E" or "D" is deleted from the 'Matrix', any data that exists is columns D, G through J remains. Same goes when a new "E" or "D" is added in a Matrix column that is before already entered data (i.e there's an "E" in the column under Position 5 and I add a new "E" in the column under Position 2)...any data in columns D, G through J doesn't adjust.
I'm not concerned about columns B or C because they use formulas to draw data based on the adjacent cell in Column which automatically changes.
 
Upvote 0
Because you can never have too many VBA answers here is mine. keiranwyllie now I don't know how much you know about excel and vba so if you have questions please ask. Now I took some liberties with your form. You will notice that you can only get one position at a time. If this is a problem let me know. But the ability to select a position from a drop down list, should make things go a little faster. If you do have more questions then answers, let us know.



VBA Code:
Sub Train1()
Dim Row1 As Long
Dim Row2 As Long
Dim Col1 As Long

Range("A3:F8").Select
    Selection.ClearContents
    Range("A3").Select
   
For Col1 = 1 To 12
If Sheets("Traniing & Gap Analysis").Range("A2") = "Position " & Col1 Then

Exit For
End If

Next Col1

Col1 = Col1 + 1

Row2 = 3

For Row1 = 3 To 7

If Sheets("Matrix").Cells(Row1, Col1) = "E" Or Sheets("Matrix").Cells(Row1, Col1) = "D" Then
Debug.Print Sheets("Matrix").Cells(Row1, 2)
Sheets("Traniing & Gap Analysis").Cells(Row2, 1) = Sheets("Traniing & Gap Analysis").Range("A2")
Sheets("Traniing & Gap Analysis").Cells(Row2, 5) = Sheets("Matrix").Cells(Row1, 1)
Sheets("Traniing & Gap Analysis").Cells(Row2, 6) = Sheets("Matrix").Cells(Row1, 15)

Row2 = Row2 + 1

End If

Next Row1

End Sub

Thanks mate, I'll have to look into this one a bit further when I have the time to digest the code. Awesome work though!!! Appreciate it!!
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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