Dim searchRange As RangeDim cell As RangeDim foundCell1 As RangeDim foundCell2 As RangeDim firstAddress1 As StringDim searchKey1 As StringDim searchKey2 As String
Set searchRange = s0_組織図.Range("G14:R" & lastRow)
If i = 116 Then Stop
searchKey1 = .Cells(i, d0_従業員名簿("姓")).ValueSet foundCell1 = searchRange.Find(what:=searchKey1, LookIn:=xlValues, lookat:=xlPart, SearchOrder:=xlByRows)If Not foundCell1 Is Nothing Then
firstAddress1 = foundCell1.Address Do Debug.Print i & Space(10) & .Cells(i, d0_従業員名簿("姓")).Value & vbTab & Space(10) & firstAddress1 & Space(10) & foundCell1.Address & Space(10) _ & .Cells(i, d0_従業員名簿("キーワード")).Value If Replace(Replace(s0_組織図.Cells(foundCell1.Row, 4).Value, " ", ""), " ", "") = .Cells(i, d0_従業員名簿("F部署")).Value Then If .Cells(i, d0_従業員名簿("キーワード")).Value <> "" Then searchKey2 = .Cells(i, d0_従業員名簿("キーワード")).Value Set foundCell2 = s0_組織図.Range("G" & foundCell1.Row & ":R" & foundCell1.Row).Find(what:=searchKey2, LookIn:=xlValues, lookat:=xlPart, _ SearchOrder:=xlByRows) If Not foundCell2 Is Nothing Then .Cells(i, d0_従業員名簿("Fグループ")).Value = s0_組織図.Cells(foundCell2.Row, 5).Value .Cells(i, d0_従業員名簿("Fグループ")).Interior.ColorIndex = 33 '青色 Exit Do End If Else .Cells(i, d0_従業員名簿("Fグループ")).Value = s0_組織図.Cells(foundCell1.Row, 5).Value .Cells(i, d0_従業員名簿("Fグループ")).Interior.ColorIndex = 33 '青色 Exit Do End If End If
Debug.Print Space(70) & searchRange.Address Set foundCell1 = searchRange.Find(what:=searchKey1, LookIn:=xlValues, lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ After:=foundCell1) If foundCell1 Is Nothing Then Exit Do ElseIf foundCell1.Address = firstAddress1 Then Exit Do End If Loop
End If