OssieMac
3/17/2009 6:39:00 PM
Hi,
In VBA (Not in C#) but it should give you an idea as to how to accomplish
what you want. You will see that I have done it in 2 stages. One to set the
background color of the cells to be cleared and then clear the colored cells.
See the comment re stopping the program if you want to see what is being
cleared.
Hope it helps.
Sub RemoveSuperfluous()
Dim rngUnit As Range
Dim c As Range
With Sheets("Sheet1")
Set rngUnit = .Range(.Cells(2, "A"), _
.Cells(.Rows.Count, "A").End(xlUp))
End With
For Each c In rngUnit
If c = c.Offset(1, 0) Then
'Set interior color for both Unit# and Team Leader
Range(c, c.Offset(0, 1)).Interior.ColorIndex = 6
End If
Next c
'Stop 'Stop here if you want to test what is being cleared
For Each c In rngUnit
If c.Interior.ColorIndex = 6 Then
'Clear contents only for both Unit# and Team Leader
Range(c, c.Offset(0, 1)).ClearContents
'Remove ColorIndex for both Unit# and Team Leader
Range(c, c.Offset(0, 1)).Interior.ColorIndex = xlNone
End If
Next c
End Sub
--
Regards,
OssieMac