VBA Code To Change Cell Color

Complete Excel VBA Course

Excel supports more than 16 million colors in a cell; hence you should know how to set the exact color in a cell. To do this, you can use RGB (Red, Green, Blue) function in VBA to set the color of a cell. The function requires 3 numbers from 0 to 255 [e.g. RGB(234,232,98)]. Below is a practice code that changes cell colors to Green, Red and Blue.

Change a Cells Background Color

VBA Code to Change Cell Color
'This function can be used to change the color of a
cell
Public Sub ChangeCellColor()
    '
    'Change cell color to green
    Sheet1.Range("C4").Interior.Color = RGB(0, 255, 0)
    '
    'Change cell color to red
    Sheet1.Range("C5").Interior.Color = RGB(255, 0, 0)
    '
    'Change cell color to blue
    Sheet1.Range("C6").Interior.Color = RGB(0, 0, 255)
    '
End Sub

VBA Code To Change Cell Color ,follow below steps:

Open an Excel file

  • Press Alt+F11
  • Insert a Module (Insert>Module) from menu bar
  • Paste the code in the module
  • Now add a shape in Excel sheet
  • Give a name to the shape like ‘Change Cell Color’
  • Right click on the shape and select ‘Assign Macro…’
VBA Code to change cell color
  • Select ‘ChangeCellColor’ from the list and click on ‘Ok’ button
  • Done, click on the shape to change the cell colors

Download Practice File

You can also practice this through our practice files. Click on the below link to download the practice file.

Recommended Articles

Excel VBA Course : Beginners to Advanced

We are offering Excel VBA Course for Beginners to Experts at discounted prices. The courses includes On Demand Videos, Practice Assignments, Q&A Support from our Experts. Also after successfully completion of the certification, will share the success with Certificate of Completion

This course is going to help you to excel your skills in Excel VBA with our real time case studies.

Lets get connected and start learning now. Click here to Enroll.

Secrets of Excel Data Visualization: Beginners to Advanced Course

Here is another best rated Excel Charts and Graph Course from ExcelSirJi. This courses also includes On Demand Videos, Practice Assignments, Q&A Support from our Experts.

This Course will enable you to become Excel Data Visualization Expert as it consists many charts preparation method which you will not find over the internet.

So Enroll now to become expert in Excel Data Visualization. Click here to Enroll.

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *