Is there a Script for changing colors based on r g b values in other cells

remejiah

New Member
Joined
Jul 13, 2016
Messages
18
Hi I am very new to using the script editor, but i need help getting a background color in column 4 based on the rgb values in columns A(r) B(g) and C(b). I would need it to change when those values change. is there any way to do this? here's a screenshot of what my sheets doc looks like.
1621994764129.png
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this:
This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window
The script runs when you enter a value in column A Or B Or C Manually
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  5/25/2021  10:39:27 PM  EDT
On Error GoTo M
If Target.Row > 1 And Target.Column < 4 Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim r As Long
r = Target.Row
Cells(r, 4).Interior.Color = RGB(Cells(r, 1), Cells(r, 2), Cells(r, 3))
End If
Exit Sub

M:
MsgBox "You may have entered a improper value in one of the cells" & vbNewLine & "You entered  " & Target.Value

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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