Home > OS >  Excel: Using either Red, Green, Blue numbers or RGB Code to fill a cell
Excel: Using either Red, Green, Blue numbers or RGB Code to fill a cell

Time:01-30

It's been awhile since I did something like this so I am struggling and could use the help. I currently have a spreadsheet where I have listed the Red, Green, and Blue values of a colour, currently I can Fill a cell with that colour if I open the menu and do custom colour. I'm wondering if there is a way that this can be done automatically?

Here is an example of what I am wanting with some blank colour cells so you can see what I am referring too:

Screenshot of Spreadsheet

Any help would be appreciated

Thank you!

CodePudding user response:

Using the RGB function:

Sub ApplyColour()
    With ActiveSheet
        Dim lastRow As Long
        lastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
        
        Dim rw As Range
        For Each rw In .Range("H5:K" & lastRow).Rows
            With rw
                .Cells(4).Interior.Color = _
                    RGB(.Cells(1).Value, .Cells(2).Value, .Cells(3).Value)
            End With
        Next
    End With
End Sub
  •  Tags:  
  • Related