ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   turns it all red, not just if boolean is true -- help with macro (https://www.excelbanter.com/excel-programming/358196-turns-all-red-not-just-if-boolean-true-help-macro.html)

Nicole Seibert

turns it all red, not just if boolean is true -- help with macro
 
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

Tom Ogilvy

turns it all red, not just if boolean is true -- help with macro
 
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

--
Regards,
Tom Ogilvy
"Nicole Seibert" wrote:

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



All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com