Conditional cell staining VBA

sofas

Active Member
Joined
Sep 11, 2022
Messages
469
Office Version
  1. 2019
Platform
  1. Windows
Welcome. I would like to obtain a code that enables me to format the cells in the table provided that the same value is present in column (C). That is, when the same value is checked, the .
background of the cells is colored with the adjacent color in column (B), and when there is no value, nothing is done


Change the background color of cells conditionally VBA


Capture d'écran 2023-12-26 130222.png
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

This should work:
VBA Code:
Sub test()
  Dim myRange As Range, cell As Range
  Set myRange = Range("F3:Q14")
  With Application
  .ScreenUpdating = False
  For Each cell In myRange
    If Not IsError(.Match(cell.Value, Columns("C"), 0)) Then
      cell.Interior.Color = Cells(.Match(cell.Value, Columns("C"), 0), "B").Interior.Color
    End If
  Next
  .ScreenUpdating = True
  End With
End Sub
 
Upvote 0
Solution
Hi,

This should work:
VBA Code:
Sub test()
  Dim myRange As Range, cell As Range
  Set myRange = Range("F3:Q14")
  With Application
  .ScreenUpdating = False
  For Each cell In myRange
    If Not IsError(.Match(cell.Value, Columns("C"), 0)) Then
      cell.Interior.Color = Cells(.Match(cell.Value, Columns("C"), 0), "B").Interior.Color
    End If
  Next
  .ScreenUpdating = True
  End With
End Sub
Thank you, this is what is needed
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,096
Latest member
Anshu121

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