For i = 2 To EndRow - 3'Ignore final 3 rows
' If not aggregate: headcount = column v
If Range("I" & i).Value <> 1 Then 'Not an Aggregate
Range("V" & i).Value = Range("U" & i).Value 'Put Headcount in "V"
'then go down to next line
'' ' If aggregate & not GPS:
ElseIf Range("I" & i).Value = 1 And Range("Z" & i).Value = 0 Then
'Exclude F(ood) & PO from counting
k = 0 'set a range object rather than Select
'you do not need to assign a variable for a single use: Range("T" & i)
Set rFound = Columns("K:S").Find( _
What:=Range("T" & i), _
After:=Range("K1"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
'test the range object for existance
If Not rFound Is Nothing Then
Firstrow = rFound.Row
''''
'''''' If Cells(rFound.Row, "I").Value <> "1" Then 'Don't count summaries
''''
'If business finance
If Cells(rFound.Row, "AG") = 1 Then ' "M" = Level 2
lev1 = "FF00"
If Cells(rFound.Row, "M") = "FF00" _
Or Cells(rFound.Row, "M") = "ET00" _
Or Cells(rFound.Row, "M") = "SCBX" _
Or Cells(rFound.Row, "M") = "FC00" _
Or Cells(rFound.Row, "M") = "PH00" Then
lev2 = ""
Else
lev2 = Cells(rFound.Row, "M")
End If 'All of the above!!
If Cells(rFound.Row, "N") = "FF3" _
Or Cells(rFound.Row, "N") = "FC3" _
Or Cells(rFound.Row, "N") = "PH2" Then
lev3 = ""
Else
lev3 = Cells(rFound.Row, "N")
End If 'All of the aboove!!
Else 'if not business finance
lev1 = Cells(rFound.Row, "L")
lev2 = Cells(rFound.Row, "M")
lev3 = Cells(rFound.Row, "N")
End If 'If Cells(rFound.Row, "AG") = 1 Then ' "M" = Level 2
'If not aggregate add up head count for any level into current rows team
'"I" = "Aggregate Code"
'"T" = "Survey Print Code" - last column level
'"O" = "Level 4"
'"P" = "Level 5"
'"Q" = "Level 6"
'"R" = "Level 7"
'"S" = "Level 8"
If (Cells(rFound.Row, "I").Value <> 1 And (Cells(rFound.Row, "K") = Range("T" & i)) _
Or lev1 = Range("T" & i) _
Or lev2 = Range("T" & i) _
Or lev3 = Range("T" & i) _
Or Cells(rFound.Row, "O") = Range("T" & i) _
Or Cells(rFound.Row, "P") = Range("T" & i) _
Or Cells(rFound.Row, "Q") = Range("T" & i) _
Or Cells(rFound.Row, "R") = Range("T" & i) _
Or Cells(rFound.Row, "S") = Range("T" & i)) Then
'' If Cells(rFound.Row, "U") <> "" Then
If Cells(rFound.Row, "I").Value <> "1" Then 'Don't count summaries
k = k + Cells(rFound.Row, "U").Value
End If 'If Cells(rFound.Row, "U") <> "" Then
End If
'' If Cells(rFound.Row, "I").Value <> "1" Then 'Don't count summaries
'''' k = k + Cells(rFound.Row, "U").Value
'Do a "Find Next" to get ALL of the rest of the required values
Do
Set rFound = Columns("K:S").FindNext(After:=rFound)
If Not rFound Is Nothing Then
If rFound.Row > Firstrow Then
'If business finance
If Cells(rFound.Row, "AG") = 1 Then ' "M" = Level 2
lev1 = "FF00"
If Cells(rFound.Row, "M") = "FF00" _
Or Cells(rFound.Row, "M") = "ET00" _
Or Cells(rFound.Row, "M") = "SCBX" _
Or Cells(rFound.Row, "M") = "FC00" _
Or Cells(rFound.Row, "M") = "PH00" Then
lev2 = ""
Else
lev2 = Cells(rFound.Row, "M")
End If 'All of the above!!
If Cells(rFound.Row, "N") = "FF3" _
Or Cells(rFound.Row, "N") = "FC3" _
Or Cells(rFound.Row, "N") = "PH2" Then
lev3 = ""
Else
lev3 = Cells(rFound.Row, "N")
End If 'All of the aboove!!
Else 'if not business finance
lev1 = Cells(rFound.Row, "L")
lev2 = Cells(rFound.Row, "M")
lev3 = Cells(rFound.Row, "N")
End If 'If Cells(rFound.Row, "AG") = 1 Then ' "M" = Level 2
'If not aggregate add up head count for any level into current rows team
'"I" = "Aggregate Code"
'"T" = "Survey Print Code" - last column level
'"O" = "Level 4"
'"P" = "Level 5"
'"Q" = "Level 6"
'"R" = "Level 7"
'"S" = "Level 8"
If (Cells(rFound.Row, "I").Value <> 1 And (Cells(rFound.Row, "K") = Range("T" & i)) _
Or lev1 = Range("T" & i) _
Or lev2 = Range("T" & i) _
Or lev3 = Range("T" & i) _
Or Cells(rFound.Row, "O") = Range("T" & i) _
Or Cells(rFound.Row, "P") = Range("T" & i) _
Or Cells(rFound.Row, "Q") = Range("T" & i) _
Or Cells(rFound.Row, "R") = Range("T" & i) _
Or Cells(rFound.Row, "S") = Range("T" & i)) Then
'' If Cells(rFound.Row, "U") <> "" Then
If Cells(rFound.Row, "I").Value <> "1" Then 'Don't count summaries
k = k + Cells(rFound.Row, "U").Value
End If 'If Cells(rFound.Row, "U") <> "" Then
End If
If Cells(rFound.Row, "I").Value <> "1" Then 'Don't count summaries
k = k + Cells(rFound.Row, "U").Value
End If
Else
Exit Do
End If 'If rFound.Row > Firstrow Then
End If 'If Not rFound Is Nothing Then
Loop
Range("V" & i).Value = k
End If 'If Not rFound Is Nothing Then
End If 'If Range("I" & i).Value = 1 And Range("Z" & i).Value = 0 Then
Next i
Set rFound = Nothing