Excel VBA, Getting the Color Code Using the Macro Recorder

In a previous article I’ve provided a sample code for getting the color code based on the fill color of a cell, Excel VBA, Get Color Code. In that example the user changes the fill color of the cell A1. After pressing the Get Code button the color code is printed in cell B1. In this article I will explain how you can get the color code using the macro recorder.

In the article Excel VBA, Formatting Cells and Ranges Using the Macro Recorder I’ve explained how you can use the macro recorder for formatting cells and ranges. The topics covered in that article were for a more general case of using the macro recorder. In this article I will focus on using the macro recorder for getting the color code only.


Step 1, Enable the Macro Recorder:

Click on the developer ribbon, then click on the record macro button:

Excel, Developer Ribbon
Click OK:

Excel, Macro Recorder Name and Location

Step 2, Change the Fill Color of a Cell:

Change the fill color of a cell to the desired color. In this example the changes will be made to cell A1. Right click the cell, then click on format cells:

Excel, Right Click Cell or Range

Select the fill tab and select the desired color. If the desired color is not available in the list of colors, click on more colors:

Excel, Fill Tab
Select a color from the standard or custom tab:

Excel, Standard Colors
Excel, Custom Colors


Step 3, Stop the Macro Recorder:

Click on the macro recorder button in the developer ribbon again to stop the macro recorder:

Excel, Stop the Macro Recorder

Step 4:

Go to the visual basics editor. A new module is created. Click on it. You will find the macro you have recorded:

Excel, Visual Basic Editor, New Module
While recording the macro if avoided any extra actions, you will probably end up with a code similar to the one in the figure below. The marked line is where you can find the color code:

Excel, VBA, Color Code, Macro Recorder

See also:

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

Leave a Reply

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