
答え1
コード:
Function MakeCompact(times As Range, shedules As Range, letter As String) As String
Dim i As Integer, n As Integer
If times.Cells.Count <> shedules.Cells.Count + 1 Then
MakeCompact = "Error. Wrong source data."
Exit Function
End If
n = times.Cells.Count
MakeCompact = ""
For i = 1 To n
If letter = shedules.Cells(1, i).Value Then
If Right(MakeCompact, 1) <> "-" Then
MakeCompact = MakeCompact & "," & times.Cells(1, i).Value & "-"
End If
Else
If Right(MakeCompact, 1) = "-" Then
MakeCompact = MakeCompact & times.Cells(1, i).Value
End If
End If
Next
MakeCompact = Mid(MakeCompact, 2)
End Function
使用法:
テーブルを作成します。
A B C D E F G
1 name 1 2 3 4 5 6
2 bob m m b m m
3 fred b m e e
4
5 m b e
6 bob
7 fred
範囲 A1:G7 はソース データです (行 1 はヘッダーです)。
範囲 A5:D7 は、入力するテーブルです。
B6に次の式を挿入します。
=MakeCompact($B$1:$G$1;$B2:$F2;B$5)
水平方向と垂直方向にドラッグしてセルを埋めます。
このアイデアは、タスク ソリューションを作成するのに十分だと思います。
PS. 注意してください - スケジュール時間の上に追加の列があります。
PPS. デバッグ後、関数を Volatile にします。