Range Shading based on another cell value

Bungraman

Board Regular
Joined
May 26, 2010
Messages
126
Hi,

I have this piece of code that checks the value in B10 then formats (shades) a range of cells B11 to B44.

How do I do it for other columns. For example:

Shade B11 to B44 based on value in B10, Shade C11 to C44 based on value in C10 ..... Shade CZ11 to CZ44 based on value in CZ10.

Also, how do I get the code to run only when the cell A1 changes.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 If Target.Address = "$B$10" Then
  Set Rng = Range("B11:B44")
    Select Case UCase(Target.Value)
        Case "1":
            Rng.Interior.ColorIndex = 15
        Case "7":
            Rng.Interior.ColorIndex = 15
    End Select
 End If
End Sub

Can anyone help??

Thanks
Bungra
 
Erik.

Because the values are already on row10, the code is not running when Cell A1 is changed. The code will only work if each cell on row 10 is changed manually. I need the code to check the contents already on row10, and apply the shading.

Regards, Bungra
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Please Please Help

This code is very manual. I need it to be a automative process. This code will only fire if the cell value in "row10" is manually changed. Row 10 contains formulas, so when the resultant formula changes it needs to fire, but it doesn't. When I force the code to run it only runs through one column only, I need it to run through columns "B" to "CZ".

Can anyone please help...


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
Dim row As Integer, col As Integer
Dim Rng As Range
 
col = Target.Column
row = Target.row
 
 If row = 10 Then
  Set Rng = Range(Cells(row + 1, col), Cells(44, col))
    Select Case UCase(Target.Value)
        Case "1":
            Rng.Interior.ColorIndex = 15
        Case "7":
            Rng.Interior.ColorIndex = 15
    End Select
 End If
 
End Sub
 
Upvote 0
After a couple of gruelling hours, I have managed to get it to work, fluked it!

This is the end code result:

Code:
Dim c As Integer, day As Integer
Dim Rng As Range
 
    For c = 2 To 100 'c refers to column number
        day = ActiveSheet.Cells(10, c) 'day refers to row 10
      Set Rng = Range(Cells(11, c), Cells(44, c))
        Select Case day
            Case "1":
                Rng.Interior.ColorIndex = 15
            Case "7":
                Rng.Interior.ColorIndex = 15
            Case Else
                Rng.Interior.ColorIndex = xlNone
        End Select
    Next
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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