LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Change cell color if...

try:

Sub blah()
For Each rw In Selection.Rows
For Each cll In rw.EntireRow.Cells
If cll.Interior.ColorIndex = 3 Then cll.Interior.ColorIndex = 1
Next cll
Next rw
End Sub


This is a quick and dirty solution, it looks at all cells in a row
individually and changes it if required. The rows that it looks at are the
entire rows of whatever cells are selected, even if they're only single cells
on that row. One slight downside is that if the user has selected several
areas (by using the ctrl key while selecting) and one area's rows include
some or all of another area's rows then those rows may be processed more than
once, but if this is a one off process it shouldn't matter.
--
p45cal


"prodeji" wrote:

Hi all

I'm reviewing a production system and trying to implement best
practices.

What I want to do is select a row/range of rows; for EACH row, if ANY
cell is color 'x', I want to run a macro to change all the cells in
that row that ARE color 'x' to color 'y'.

This works:

Sub ChangeColor()
Dim rCell As Range
For Each rCell In Selection.Cells
If Selection.Cells.Interior.ColorIndex = 3 Then
Selection.Cells.Interior.ColorIndex = 1
End If
Next rCell
End Sub

(yeah, I know it's primitive)
but only if ALL the cells in the selection/selected row(s) is/are
color 'x'.

Hence if the user selects entire rows rather than concise selections,
as they are likely to do, the macro will not work, because it's more
than likely that only a portion of the selected row(s) will be color
'x' and the rest will have no fill.

What adjustments do I need to make for the macro to have desired
results whether selections are concise or not?


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change tab color based on current color of a cell MarkT Excel Discussion (Misc queries) 0 May 22nd 08 05:46 PM
Excel: Syntax to change cell color based on color of another cell davew18 Excel Worksheet Functions 1 January 4th 07 01:24 PM
change fill color of a range of cells based on color of a cell? DarMelNel Excel Programming 0 March 2nd 06 06:35 PM
How to change the default Border, Font Color, and Cell Color Elijah Excel Discussion (Misc queries) 3 November 2nd 05 11:52 PM
Browse Forms Controls and change TextBox color based on cell color StefanW Excel Programming 2 November 21st 04 07:06 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"