[lnkForumImage]
TotalShareware - Download Free Software
Usa Forum
 Home | Login | Register | Search 


 

Forums >

rec.games.trading-cards.jyhad

http://477.girltv.com.tw

2 Answers

OssieMac

3/17/2009 6:39:00 PM

0

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


OssieMac

3/17/2009 6:51:00 PM

0

My apologies. I made some changs to the program after initial testing and
then did not look at the results carefully enough after making those changes.
Replace it with the following code.

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.Offset(1, 0), c.Offset(1, 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