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.
'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
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
How to use VBA to open Workbook in Excel? There are few VBA codes which are commonly used by every developer. One of them is giving an option to user to browse a file. Below is a…
Did you come across any requirement where you want the user to interact with a sheet only through VBA Form? Here is a simple code which can help you.
How to Add Outlook Reference in Excel VBA? To automate Outlook based tasks from Excel you need to add Outlook Object Library (Microsoft Outlook XX.X Object Library) in Excel References. You can follow below steps…
Introduction :- ColorIndex in Excel VBA Today let’s try to understand how ColorIndex property in Excel VBA works. It is an easy and effective way to quickly complete the development. ColorIndex property is normally used…
VBA Code to send Outlook Emails Sending bulk emails is a very common activity, there are many office activities that need a person to send bulk emails to single or multiple recipients. You also may…
VBA Code to check if folder exist Validation is one of the important parts of any programming language. As per few studies, 60% of the code is focused on validating input or output. In this…
One Comment