SheriffWoody
New Member
- Joined
- Jul 7, 2015
- Messages
- 3
I am aiming to select a column and highlight any duplicate values as green.
I would then like to instruct Excel to do 1 of 2 things in an If Then structure for the given range:
1) filter for any potential green cells and then end sub with "Complete" msgbox
OR
2) if no cells were highlighted green as a result of the first part of the code then display "No duplicate values found" and end sub with "Complete" msgbox
Currently, the below code highlights duplicates green (no issues there) as well as filtering when duplicates are present. I'm having difficulty constructing the If_Then ... ElseIf statement so that when NO duplicates are found, a message appears stating "No Duplicates Found" and then closing the sub.
Any help would be greatly appreciated! I just starting self teaching VBA on Thursday so go easy
- SheriffWoody
CODE:
'Identify Dups with green highlight
Dim DupCell As Variant
Dim DupRange As Range
Range("C5").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 3).Select
Range(Selection, Selection.End(xlUp)).Select
Set DupRange = Selection
DupRange.Interior.ColorIndex = xlNone
For Each DupCell In DupRange
If Application.WorksheetFunction.CountIf(DupRange, DupCell) > 1 Then
DupCell.Interior.ColorIndex = 4
End If
Next
'Filter for green dups
Application.ScreenUpdating = True
For Each DupCell In DupRange
If DupCell.Interior.ColorIndex = 4 Then
DupRange.AutoFilter Field:=6, Criteria1:=RGB(0, 255, 0), Operator:=xlFilterCellColor
ElseIf DupCell.Interior.ColorIndex = 0 Then
MsgBox "No duplicates found!", vbInformation, "* * * C O M P L E T E * * *"
End If
Next
MsgBox "Duplicate Check Complete"
I would then like to instruct Excel to do 1 of 2 things in an If Then structure for the given range:
1) filter for any potential green cells and then end sub with "Complete" msgbox
OR
2) if no cells were highlighted green as a result of the first part of the code then display "No duplicate values found" and end sub with "Complete" msgbox
Currently, the below code highlights duplicates green (no issues there) as well as filtering when duplicates are present. I'm having difficulty constructing the If_Then ... ElseIf statement so that when NO duplicates are found, a message appears stating "No Duplicates Found" and then closing the sub.
Any help would be greatly appreciated! I just starting self teaching VBA on Thursday so go easy
- SheriffWoody
CODE:
'Identify Dups with green highlight
Dim DupCell As Variant
Dim DupRange As Range
Range("C5").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 3).Select
Range(Selection, Selection.End(xlUp)).Select
Set DupRange = Selection
DupRange.Interior.ColorIndex = xlNone
For Each DupCell In DupRange
If Application.WorksheetFunction.CountIf(DupRange, DupCell) > 1 Then
DupCell.Interior.ColorIndex = 4
End If
Next
'Filter for green dups
Application.ScreenUpdating = True
For Each DupCell In DupRange
If DupCell.Interior.ColorIndex = 4 Then
DupRange.AutoFilter Field:=6, Criteria1:=RGB(0, 255, 0), Operator:=xlFilterCellColor
ElseIf DupCell.Interior.ColorIndex = 0 Then
MsgBox "No duplicates found!", vbInformation, "* * * C O M P L E T E * * *"
End If
Next
MsgBox "Duplicate Check Complete"