Loop through sheet formatting columns while column C is true?


Posted by Gary on November 17, 2001 12:16 PM

Hi,
I am trying to write a macro that will loop through each row checking to see if the value in column C is TRUE, if it is I need to format the row blue and then carry on with the loop until it reaches a false.

I have data in column B that may or may not have more than one instance of the same value in it. I need the macro to format blue any that have >= 1 instance of that value in that column.

I can't see any other way of comparing the values other than sorting column B in order and then inserting a column with the formula's

=IF(ISBLANK(B10),FALSE,IF(B10=B11,TRUE,IF(B10=B9,TRUE,FALSE)))

Trouble with this is you have to have an entry that isn't counted that will always stay at the top when sorted otherwise you end up with a #REF once you have sorted the Rows by column B.

Basically all the macro has to do is colour blue any row which has a value in column B that is duplicated in Column B.

Any help would be much appreciated :o)

Gary



Posted by Olaf on November 17, 2001 1:15 PM

you can try this :


Range("B1").Select
numberofrows = 20 'choose yourself
For i = 1 To numberofrows
tempvalue = ActiveCell.Offset(i, 0)
For j = 1 To numberofrows
If i = j Or tempvalue = "" Then
Else
If ActiveCell.Offset(j, 0) = tempvalue Then
ActiveCell.Offset(i, 0).EntireRow.Font.ColorIndex = 41
End If
End If
Next j
Next i

good luck,

Olaf