
2 つの列があります。
Column A Column B
1 Course ID Professors <---- (Column Headers)
2 1179/03 Professor-1
3 1179/03
4 1179/03
5 1300/20 Professor-2
6 1300/20 Professor-3
7 1300/21 Professor-2
8 1300/21 Professor-3
9 1300/21 Professor-4
10 1300/21 Professor-4
11 1300/21 Professor-4
各コース ID には複数の教授を割り当てることができます。
同じシートの別の部分にコース ID のリストがあり、数式を使用して割り当てられた教授を挿入したいと考えています。
Column D Column E
1 Course ID Professors <--- (Column Header)
2 1179/03 Professor-1
3 1300/20 Professor-2, Professor-3
4 1300/21 Professor-2, Professor-3, Professor-4
データを手動で提供しますあ、Bそしてだ列に結果を表示したい場合、E2、E3、E4Match/Index
またはによってVLOOKUP
。
私の制限は、新しい列を追加できないことと、ユーザーが特定の列に従ってデータを並べ替えることを制限する可能性があることです。
どなたか助けていただけませんか。
答え1
投稿したデータに類似したデータを使用したこの短いマクロ:
Sub Roster()
Dim rc As Long, i As Long, j As Long, v As String
Dim nA As Long, nB As Long, nD As Long, vv As String
rc = Rows.Count
nA = Cells(rc, 1).End(xlUp).Row
nB = Cells(rc, 2).End(xlUp).Row
nD = Cells(rc, 4).End(xlUp).Row
For i = 2 To nD
v = Cells(i, 4)
vv = ""
For j = 2 To nA
If v = Cells(j, 1) And Cells(j, 2) <> "" And InStr(1, vv, Cells(j, 2)) = 0 Then
vv = vv & "," & Cells(j, 2)
End If
Next j
Cells(i, 5) = Mid(vv, 2)
Next i
End Sub
生成されます: