Searching for Boolean Cells

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

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top