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.
Contents
Step 1, Enable the Macro Recorder:
Click on the developer ribbon, then click on the record macro button:
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:
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:
Select a color from the standard or custom tab:
Step 3, Stop the Macro Recorder:
Click on the macro recorder button in the developer ribbon again to 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:
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:
See also:
- Excel VBA, RGB
- Excel VBA, Get Color Code
- Excel VBA, Color Code
- Excel VBA, Formatting Cells and Ranges Using the Macro Recorder
- Excel VBA, ColorConstants
- Excel VBA, XlRgbColor
- VBA Excel, Colors
- Excel VBA, Color Dialog xlDialogEditColor
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