Coloring cells based on data from other sheet

PWSY86

New Member
Joined
Nov 22, 2015
Messages
48
Hi,

I have problem with this formula:

Code:
Sub Cell_color()Dim MyWorkbook As Workbook
Dim Matrix As Worksheet
Dim Help As Worksheet
Dim Data As Worksheet


Set MyWorkbook = ActiveWorkbook
Set Matrix = MyWorkbook.Sheets("Matrix")
Set Data = MyWorkbook.Sheets("Data")
Set Help = MyWorkbook.Sheets("Help")


    If Data.Range("B3:B22").Value = Help.Range("B2").Value Then
        Matrix.Range("B2:U2").Interior.ColorIndex = 37
        Else
        Matrix.Range("B2:U2").Interior.ColorIndex = 78
    End If
End Sub

It's all I got so far.

What I want is macro which checks if cell ranges (B3:B22)(E3:E22)(H3:H22)(K3:K22)(N3:N16)(Q3:Q13)(U3:U13) in sheet "Data" contains one of value from B2 in sheet "Help" and then colors cell range in sheet "Matrix" with wanted colors.

I hope it's clear enough for you all.

Link to test file: http://1drv.ms/23NdfVM

best regards,
Przemek
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
The entire data range does not have a value.
This code check each cell in the specified range for the target value
Code:
Option Explicit

Sub Cell_color()

    Dim MyWorkbook As Workbook
    Dim Matrix As Worksheet
    Dim Help As Worksheet
    Dim Data As Worksheet
    Dim rngCell As Range
    Dim bMatch As Boolean
    
    Set MyWorkbook = ActiveWorkbook
    Set Matrix = MyWorkbook.Sheets("Matrix")
    Set Data = MyWorkbook.Sheets("Data")
    Set Help = MyWorkbook.Sheets("Help")

    For Each rngCell In Data.Range("B3:B22,E3:E22,H3:H22,K3:K22,N3:N16,Q3:Q13,U3:U13")
        If rngCell.Value = Help.Range("B2").Value Then
            bMatch = True
            Exit For
        End If
    Next
    If bMatch Then
        Matrix.Range("B2:U2").Interior.ColorIndex = 37
        Else
        Matrix.Range("B2:U2").Interior.ColorIndex = 78
    End If
    
    Set Matrix = Nothing
    Set Data = Nothing
    Set Help = Nothing
    Set MyWorkbook = Nothing
    
End Sub
 
Upvote 0
Thanks for your time and reply, it works now. I didn't exactly precise my problem. I need code to check if data range from DATA sheet maches data from HELP sheet. If yes then color cells in MATRIX sheet with specified colors for example when data is TO DO then color cells with yellow; attention would be red etc.
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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