This is the table to show how the names are written in the fort column.
I need to identify the column/attribute's values (the 5 values in italics) and assign it to that name.
I made a command-click button named Values
that I want to output the name of the row/faculty reviewed and the columns that were indicated with an "XXXXX
". I want to go through each cell and if an XXXXX
is present, print the column's value next to the name of the row's faculty.
This is the code I was previously using:
Private Sub loop_through_table()
Dim cell As Range ' loop through cells, check for names
Dim col As Range 'loop through Columns, check for XXXXX
Dim lr As Long ' last active row
Dim ws As Worksheet: Set ws = Sheets("Sheet4")
Dim res As String ' will store result
Dim i As Long 'for loop counter
Dim maxL As Long ' rightmost last active column
lr = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
maxL = ws.Cells(4, Columns.Count).End(xlToLeft).Column
For i = 5 To lr - 1 ' skip the initials, hence Step 2
res = "" ' reset of result
Set cell = ws.Cells(i, 1)
res = cell + ":"
For Each col In ws.Range(Cells(i + 1, 2), Cells(i + 1, maxL))
If col = "XXXXX" Then 'if we found xxxxx
If Right(res, 1) = ":" Then 'we don't want comma on first argument
res = res + " " + ws.Cells(3, col.Column)
Else
res = res + ", " + ws.Cells(3, col.Column)
End If
End If
Next col
ws.Cells(i, maxL + 3) = res 'print result to rightmost column + 2
Next i
End Sub
So the output would be:
First Last: Physical, CyberSecurity
First2 Last2: Mathematical, Artificial Intelligence
and so on...
Could I also print by specific faculty instead of printing every row?