Conditional Formatting Across Worksheets

Chris11

New Member
Joined
Sep 20, 2011
Messages
19
Hi All,

New to this forum but im hoping you can help, as I'm struggling to get this task done at work.

I've got a conditional formatting macro for my worksheet as I have more than 3 conditions.
But now I need to use information from another worksheet (in the same workbook) in the macro.
Basically I dont know how to reference the new worksheet.

This is what I Currently have:



Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPlage = Range("D5:D69")
For Each Cell In MyPlage

If Cell.Value = "8601" Then
Cell.Interior.ColorIndex = 41
End If

If Cell.Value = "8501" Then
Cell.Interior.ColorIndex = 43
End If

If Cell.Value = "4901" Then
Cell.Interior.ColorIndex = 46
End If

If Cell.Value = "4902" Then
Cell.Interior.ColorIndex = 44
End If

If Cell.Value = "3802" Then
Cell.Interior.ColorIndex = 47
End If

If Cell.Value = "3802(D)" Then
Cell.Interior.ColorIndex = 7
End If

If Cell.Value = "8504" Then
Cell.Interior.ColorIndex = 18
End If

If Cell.Value = "Not listed" Then
Cell.Interior.ColorIndex = 15
End If


Next
End Sub




Thanks in advance!

Chris A
 
Forgot a bit:
Code:
Set rngData = Sheet3.Range("A2:A40")
        For Each rngCell In Sheet1.Range("D6:N71").Cells
        Colourcell rngCell, rngData
        Next rngCell

No - changing a colour does not trigger any events you can trap, but you should be able to use the Worksheet_DeActivate event of Sheet3 to run the code to recolour the cells.
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Forgot a bit:
Code:
Set rngData = Sheet3.Range("A2:A40")
        For Each rngCell In Sheet1.Range("D6:N71").Cells
        Colourcell rngCell, rngData
        Next rngCell

No - changing a colour does not trigger any events you can trap, but you should be able to use the Worksheet_DeActivate event of Sheet3 to run the code to recolour the cells.


Hmm ok.

I think ive got something wrong with this part on Sheet3 code:

Code:
Sub Worksheet_Change(ByVal Target As Range)

Debug is not liking it!
 
Upvote 0
Full code please? (that line is fine)
 
Upvote 0
Full code please? (that line is fine)

Code:
Sub Worksheet_Change(ByVal Target As Range)
        Set rngData = Sheet3.Range("A2:A40")
        For Each rngCell In Sheet1.Range("D6:N71").Cells
        Colourcell [B]rngCell[/B], rngData
        Next rngCell
End Sub

First line is highlighted yellow. Same compile error as before.
Might be the part i put in bold ?
 
Upvote 0
Need to declare the variables:
Code:
Sub Worksheet_Change(ByVal Target As Range)
    Dim rngCell as Range
    Dim rngData as range
        Set rngData = Sheet3.Range("A2:A40")
        For Each rngCell In Sheet1.Range("D6:N71").Cells
        Colourcell rngCell, rngData
        Next rngCell
End Sub
 
Upvote 0
YAY!! Finally works how i wanted it to!

Thanks for all your help Rory

...Lets see if my boss cares now...:(
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,244
Members
453,152
Latest member
ChrisMd

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