Color a row if any cells of the same row is colored in grey

schinois

New Member
Joined
Oct 18, 2008
Messages
6
Hello,

I created a button to color selected cell(s).

I would like to have a macro which does the following:

Where do I apply the formula?
The formula is first applied to the cell range "A1:Z1" (part of a row).
Then, I would like to apply this formula to each row from "A15" to "A2189".

What does the formula do?
if I color in grey one any of the cells in the range "A1:Z1" (for example), then the whole range "A1:Z1" is colored with the same color and all the text is striken-out.

Thanks for the support ;)

Stephane
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
untested but should be a good start.

Sub Colour_Out_Row(Given_Range As Range)
Dim No_of_Rows As Long
Dim No_of_Cols As Long

Dim r As Long
Dim c As Long
Dim k As Long

'Note that 15 is grey


No_of_Rows = Given_Range.Rows.Count
No_of_Cols = Given_Range.Columns.Count

MsgBox No_of_Rows & No_of_Cols

For c = 1 To No_of_Cols
For r = 1 To No_of_Rows
If Given_Range.Cells(r, c).Interior.ColorIndex = 15 Then
For k = 1 To No_of_Rows
Given_Range.Cells(c, k).Interior.ColourIndex = 15
Next k
End If

Next r
Next c


End Sub
 
Upvote 0
Sub Colour_Out_Row(Given_Range As Range)
Dim No_of_Rows As Long
Dim No_of_Cols As Long

Dim r As Long
Dim c As Long
Dim k As Long

'Note that 15 is grey


No_of_Rows = Given_Range.Rows.Count
No_of_Cols = Given_Range.Columns.Count

MsgBox No_of_Rows & No_of_Cols

For c = 1 To No_of_Cols
For r = 1 To No_of_Rows
If Given_Range.Cells(r, c).Interior.ColorIndex = 15 Then
For k = 1 To No_of_Rows
Given_Range.Cells(k, c).Interior.ColorIndex = 15
Next k
End If

Next r
Next c


End Sub

Correction as had ColourIndex rather than ColorIndex.
 
Upvote 0

Forum statistics

Threads
1,215,829
Messages
6,127,129
Members
449,361
Latest member
VBquery757

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top