VBA Code To Change Cell Color
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
'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…’
- Select ‘ChangeCellColor’ from the list and click on ‘Ok’ button
- Done, click on the shape to change the cell colors
You can also read this post to know how to get RGB Codes of a Color.
VBA Code to Count Color Cell based on Conditional Formatting
Download Practice File
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.
Use Automated Excel Utility Tools to increase productivity
Hope you are enjoying learning Excel with us, if you want any support related to this article, please do comment else you can ask questions in Excel Community