Originally Posted by
Paul_Hossler
I used col T not U since you had T in the sample
Changed the Group strings from your requirements to match what was in the sample
Many ways to do it. I used Selects, but IF/Then's would work
[vba]
Option Explicit
'Check each row to see if the criteria meets the parameters.
'If the "LOB_Code" is ERPK, CSNA, or GL
' Then check if "Groupname" is Carrier Parent 1 or Carrier Parent 2.
' If Carrier Parent 1, then check if "Com Rate %" is 22.5% and, if a match, make the cell in column U equal to "Flag 1"
' If Carrier Parent 2, then check if "Com Rate %" is 20% and, if a match, make the cell in column U equal to "Flag 1"
'If the "LOB_Code" is CPKG, EPKG, or ComPKG
' Then check if "GroupName" is Carrier Parent 2 or Carrier Parent 4
' If Carrier Parent 2, then check if "Com Rate %" is 22%, and if a match, make the cell in column U equal to "Flag 2"
' If Carrier Parent 4, then check if "Com Rate %" is 20%, and if a match, make the cell in column U equal to "Flag 2"
'If the row's column U cell has any value, the cell in column A should read "Flagged"
Sub Flag()
Const iLOB As Long = 8
Const iGroup As Long = 10
Const iCommRate As Long = 19
Const iFlagged12 As Long = 20 'Col T -- not col U
Const iFlag As Long = 1
Dim rRow As Range, rData As Range
Set rData = ActiveSheet.Cells(1, 1).CurrentRegion
Set rData = rData.Cells(2, 1).Resize(rData.Rows.Count - 1, rData.Columns.Count)
For Each rRow In rData.Rows
With rRow
Select Case .Cells(iLOB).Value
Case "ERPK", "CSNA", "GL"
Select Case .Cells(iGroup).Value
Case "Carrier Parent Group 1"
If .Cells(iCommRate).Value = 0.225 Then
.Cells(iFlagged12).Value = "Flag 1"
.Cells(iFlag).Value = "Flagged"
End If
Case "Carrier Parent Group 2"
If .Cells(iCommRate).Value = 0.2 Then
.Cells(iFlagged12).Value = "Flag 1"
.Cells(iFlag).Value = "Flagged"
End If
End Select
Case "CPKG", "EPKG", "ComPKG"
Select Case .Cells(iGroup).Value
Case "Carrier Parent Group 2"
If .Cells(iCommRate).Value = 0.22 Then
.Cells(iFlagged12).Value = "Flag 2"
.Cells(iFlag).Value = "Flagged"
End If
Case "Carrier Parent Group 4"
If .Cells(iCommRate).Value = 0.2 Then
.Cells(iFlagged12).Value = "Flag 2"
.Cells(iFlag).Value = "Flagged"
End If
End Select
End Select
End With
Next
End Sub
[/vba]
Paul