P
prodeji
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?
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?