Searching for Boolean Cells
Hi,
I'm using the following statement to set an object equal to the boolean cells in a worksheet. After that I can colour them to identify their location. However if there are no such cells in the worksheet an error is generated. I could use resume next and clear the errors but a neater way would obviously be a test for the existence of boolean cells before the colouring loop is entered dim cellcollection as object Set cellCollection = Selection.SpecialCells(xlCellTypeConstants, xlLogical) For Each cell In cellCollection ActiveSheet.Cells(cell.Row, cell.Column).Interior.ColorIndex = booleanColour Next cell Suggestions...Thanks Chris |
Searching for Boolean Cells
You don't need to rely on an error:
Sub Macro1() Dim cell As Range For Each cell In Selection If Application.IsLogical(cell.Value) Then cell.Interior.ColorIndex = 3 End If Next cell End Sub -- Gary''s Student "Chris Gorham" wrote: Hi, I'm using the following statement to set an object equal to the boolean cells in a worksheet. After that I can colour them to identify their location. However if there are no such cells in the worksheet an error is generated. I could use resume next and clear the errors but a neater way would obviously be a test for the existence of boolean cells before the colouring loop is entered dim cellcollection as object Set cellCollection = Selection.SpecialCells(xlCellTypeConstants, xlLogical) For Each cell In cellCollection ActiveSheet.Cells(cell.Row, cell.Column).Interior.ColorIndex = booleanColour Next cell Suggestions...Thanks Chris |
All times are GMT +1. The time now is 06:08 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com