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
Table of Content How does testing help? How should I test my tool or application? How does Dummy Data Generator tool helps in testing? How do I use this tool? From many years I have…
VBA to Read Excel Data Using Connection String Sometimes as a programmer you need to read heavy (more then 5 MB) Excel files. There are two ways you can read data from Excel files: Open…
VBA code that will sum cells by its color through excel function. This code will really help in making the analysis and presentation better.
This Excel VBA Code helps to Get User Name. Here is an example environ(username) or Application.username.This macro gets the username from active directory.
VBA Code To Add Items In Listbox Control Using ListBox in Userform is very common. You can use ListBox.AddItem function to add items in the listbox.; however, it is little difficult to add items in…
Have you ever got into situation in office where you need to count the cells in Excel sheet with specific color? If yes then you can use following code which counts the number of cells…
One Comment