ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting cells by color? (https://www.excelbanter.com/excel-programming/284126-selecting-cells-color.html)

Gary Adamson[_2_]

Selecting cells by color?
 
Is there a way to select cells based on color?
Do I need to do this with a program or does Excel have a
function to do this?


Sub FindSameCells()
ci = ActiveCell.Interior.ColorIndex
For Each c In ActiveSheet.UsedRange
If c.Interior.ColorIndex = ci Then
'Add this cell to the SelectionRange
end if
Next c
SelectionRange.Select
End Sub



Tom Ogilvy

Selecting cells by color?
 
Sub FindSameCells()
Dim rng as Range, c as Range
Dim ci as Long
ci = ActiveCell.Interior.ColorIndex
For Each c In ActiveSheet.UsedRange
If c.Interior.ColorIndex = ci Then
if rng is nothing then
set rng = c
else
set rng = Union(c,rng)
end if
end if
Next c
rng.Select
End Sub

No built in support for this.

--
Regards,
Tom Ogilvy

"Gary Adamson" wrote in message
...
Is there a way to select cells based on color?
Do I need to do this with a program or does Excel have a
function to do this?


Sub FindSameCells()
ci = ActiveCell.Interior.ColorIndex
For Each c In ActiveSheet.UsedRange
If c.Interior.ColorIndex = ci Then
'Add this cell to the SelectionRange
end if
Next c
SelectionRange.Select
End Sub






All times are GMT +1. The time now is 08:13 PM.

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