|
Sub test()
Dim rngF As Range, rngT As Range
Dim dicX As Object, dicY As Object
Dim w, k As Long
Dim r As Range, c As Range
Dim 作業 As String, 区分
Set rngF = Range("R11:DI41")
Set rngT = Range("F50:P69")
ReDim w(1 To rngT.Rows.Count, 1 To rngT.Columns.Count)
Set dicX = CreateObject("scripting.dictionary")
Set dicY = CreateObject("scripting.dictionary")
For k = 1 To rngT.Rows.Count
作業 = rngT(k, -4).Value
If 作業 <> "" Then dicY(作業) = k
Next
For k = 1 To rngT.Columns.Count Step 2
区分 = rngT(-1, k).Interior.ColorIndex
dicX(区分) = k
Next
For Each r In rngF.Rows
作業 = ""
For Each c In r.Cells
区分 = c.Interior.ColorIndex
If Not dicX.exists(区分) Then 区分 = xlNone
If c.Value <> "" Then 作業 = c.Value
If Not dicY.exists(作業) Then
If 区分 <> xlNone Or 作業 <> "" Then
Application.Goto c, -1
MsgBox c.Address(0, 0) & "セルの作業番号不明"
Exit Sub
End If
End If
If c.Value <> "" Or 区分 <> xlNone Then
w(dicY(作業), dicX(区分)) = w(dicY(作業), dicX(区分)) + 1
End If
Next
Next
rngT.Value = w
End Sub
|
|