turns it all red, not just if boolean is true -- help with macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Okay.
c, rbn, rbo and rnbo are ranges. DupsFound is boolean. The logic is if
this cell is this workbook on this sheet in this range (see ranges above)
equals the value of this cell in this workbook on this sheet in this range
(again see above) then set the boolean to true and color the cell red.
Any ideas why the entire column turns red?
First, here is an example of my declared ranges:
temp1 = InputBox("What is the name of the new Demand Workbook?")
Set BANew = Workbooks(temp1 & ".xls").Sheets(1)
t1 = BANew.Cells(Rows.Count, 1).End(xlUp).Row
Set rbn = BANew.Range(BANew.Cells(3, 1), BANew.Cells(t1, 1).End(xlDown))

Then here is where I check for duplicates between workbook and different
worksheets within those workbook:

For Each c In rbn.Cells
If Application.CountIf(rbo, c.Value) > 0 Then _
DupsFound = True
c.Interior.ColorIndex = 3
If Application.CountIf(rnbo, c.Value) > 0 Then _
DupsFound = True
c.Interior.ColorIndex = 3
Next

If you need clarification just let me know:
Nicole
 
Your problem is that you IF statement are screwed up:

For Each c In rbn.Cells
If Application.CountIf(rbo, c.Value) > 0 Then
DupsFound = True
c.Interior.ColorIndex = 3
End if
If Application.CountIf(rnbo, c.Value) > 0 Then
DupsFound = True
c.Interior.ColorIndex = 3
End if
Next
 
Back
Top