Conditional formatting a cell depending on another cell

BakirDZ

New Member
Joined
Sep 7, 2023
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
Hello,

I would appreciate if anyone could help me with what I'm trying to do (not sure if it's possible though)

I have 2 lists of products required by 2 customers and some products are required by both customers, I go through the customer_1 list item by item and check if it's available in stock, if it's not I color its quantity with red. I wonder if there is a way to make excel do the same with customer_2 by coloring the cells of quantity for the products that are required by customer_2 and already been marked as unavailable for customer_1

Thank you guys in advance!

Excel_Lists.jpg
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Welcome to the Board!

Conditional Formatting can only run off of cell's values, not the manual formatting applied to them.
If you are manually coloring the cells for Customer_1, you cannot Conditional Format cells for Customer_2 based on that. You would require VBA to color their cells.
If the cells for Customer_1 were being formatted via some Conditional Formatting rule, you should be able to apply the same Conditional Formatting rule to Customer_2.
 
Upvote 1
Welcome to the Board!

Conditional Formatting can only run off of cell's values, not the manual formatting applied to them.
If you are manually coloring the cells for Customer_1, you cannot Conditional Format cells for Customer_2 based on that. You would require VBA to color their cells.
If the cells for Customer_1 were being formatted via some Conditional Formatting rule, you should be able to apply the same Conditional Formatting rule to Customer_2.
Hey Joe4, thanks for your reply and welcome

Do you mean that I need VBA to do this or it's not possible at all if I color the cells manually ? and if it's possible with VBA I would appreciate your help with it if possible, Thanks
 
Upvote 0
You need VBA if you are coloring the cells manually.
Here is VBA code that will do what you want, based on your example. I added comments to the code to explain what each step is doing:
VBA Code:
Sub MyCopyFormatting()

    Dim lr1 As Long
    Dim lr2 As Long
    Dim i As Long
    Dim j As Long
    Dim prd As String
  
    Application.ScreenUpdating = False
  
'   Find last row in column B with data
    lr1 = Cells(Rows.Count, "B").End(xlUp).Row
  
'   Find last row in column E with data
    lr2 = Cells(Rows.Count, "E").End(xlUp).Row
  
'   Loop through all rows in column B starting with row 4
    For i = 4 To lr1
'       See if column C is highlighted
        If Cells(i, "C").Interior.Pattern = xlNone Then
'           Do nothing if no highlighting
        Else
'           Capture value from column B
            prd = Cells(i, "B").Value
'           Loop through column E looking for matches
            For j = 4 To lr2
                If Cells(j, "E") = prd Then
'                   Copy formatting from column C to column F
                    Cells(i, "C").Copy
                    Cells(j, "F").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
                        SkipBlanks:=False, Transpose:=False
                    Application.CutCopyMode = False
                End If
            Next j
        End If
    Next i
  
    Application.ScreenUpdating = True
  
End Sub

And here is my proof-of-concept.

Before Macro is run:
1694217019167.png

After Macro is run:
1694217058636.png
 
Upvote 1
Solution
You need VBA if you are coloring the cells manually.
Here is VBA code that will do what you want, based on your example. I added comments to the code to explain what each step is doing:
VBA Code:
Sub MyCopyFormatting()

    Dim lr1 As Long
    Dim lr2 As Long
    Dim i As Long
    Dim j As Long
    Dim prd As String
 
    Application.ScreenUpdating = False
 
'   Find last row in column B with data
    lr1 = Cells(Rows.Count, "B").End(xlUp).Row
 
'   Find last row in column E with data
    lr2 = Cells(Rows.Count, "E").End(xlUp).Row
 
'   Loop through all rows in column B starting with row 4
    For i = 4 To lr1
'       See if column C is highlighted
        If Cells(i, "C").Interior.Pattern = xlNone Then
'           Do nothing if no highlighting
        Else
'           Capture value from column B
            prd = Cells(i, "B").Value
'           Loop through column E looking for matches
            For j = 4 To lr2
                If Cells(j, "E") = prd Then
'                   Copy formatting from column C to column F
                    Cells(i, "C").Copy
                    Cells(j, "F").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
                        SkipBlanks:=False, Transpose:=False
                    Application.CutCopyMode = False
                End If
            Next j
        End If
    Next i
 
    Application.ScreenUpdating = True
 
End Sub

And here is my proof-of-concept.

Before Macro is run:
View attachment 98476
After Macro is run:
View attachment 98477
That's exactly what I was trying to do, thank you so much!
 
Upvote 0
You are welcome.
I am glad I was able to help and that it worked out well for you!
 
Upvote 1

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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