Retrieve Excel Cell’s Font & Fill RGB Color Code
What This Does
Appearance can play a huge factor in the professionalism of your spreadsheet’s presentation. Often there are times when I want to match a specific color that falls outside the current spreadsheet’s Theme Color palette. There are also times when I want to match an Excel color so I can use it inside another program (ie Photoshop, Ribbet, etc…). The best way to guarantee you are using the exact same color is to find that specific color’s color code. There are two ways to do this: manually or macro-matically (yeah, I just invented that word). Since I’m such a nice guy, I’m going to walk you through how to do both! Enjoy 🙂
Manual Way To Find RGB Color Code
- Select a cell that contains the fill color you want to lookup
- Click the Paint Bucket button on your Home Ribbon tab
- Select the More Colors option
- Go to the Custom tab and make sure Color Model = RGB
- You will now see the RGB color code for your selected cell’s fill
This method can be performed similarly for cell font & border colors. The only step you will need to change from above is step #2.
Now With VBA Code
Below I’ve posted the VBA code that determines the color code. These macros can easily be pasted into your Personal Macro file if you think you will use this code often.
Figuring Out The Fill Color
Sub GetRGBColor_Fill() 'PURPOSE: Output the RGB color code for the ActiveCell's Fill Color 'SOURCE: www.TheSpreadsheetGuru.com Dim HEXcolor As String Dim RGBcolor As String HEXcolor = Right("000000" & Hex(ActiveCell.Interior.Color), 6) RGBcolor = "RGB (" & CInt("&H" & Right(HEXcolor, 2)) & _ ", " & CInt("&H" & Mid(HEXcolor, 3, 2)) & _ ", " & CInt("&H" & Left(HEXcolor, 2)) & ")" MsgBox RGBcolor, vbInformation, "Cell " & ActiveCell.Address(False, False) & ": Fill Color" End Sub
Figuring Out The Font Color
Sub GetRGBColor_Font() 'PURPOSE: Output the RGB color code for the ActiveCell's Font Color 'SOURCE: www.TheSpreadsheetGuru.com Dim HEXcolor As String Dim RGBcolor As String HEXcolor = Right("000000" & Hex(ActiveCell.Font.Color), 6) RGBcolor = "RGB (" & CInt("&H" & Right(HEXcolor, 2)) & _ ", " & CInt("&H" & Mid(HEXcolor, 3, 2)) & _ ", " & CInt("&H" & Left(HEXcolor, 2)) & ")" MsgBox RGBcolor, vbInformation, "Cell " & ActiveCell.Address(False, False) & ": Font Color" End Sub
Using VBA Code Found On The Internet
Now that you’ve found some VBA code that could potentially solve your Excel automation problem, what do you do with it? If you don’t necessarily want to learn how to code VBA and are just looking for the fastest way to implement this code into your spreadsheet, I wrote an article (with video) that explains how to get the VBA code you’ve found running on your spreadsheet.
Getting Started Automating Excel
Are you new to VBA and not sure where to begin? Check out my quickstart guide to learning VBA. This article won’t overwhelm you with fancy coding jargon, as it provides you with a simplistic and straightforward approach to the basic things I wish I knew when trying to teach myself how to automate tasks in Excel with VBA Macros.
Also, if you haven’t checked out Excel’s latest automation feature called Power Query, I have put together a beginner’s guide for automating with Excel’s Power Query feature as well! This little-known built-in Excel feature allows you to merge and clean data automatically with little to no coding!
How Do I Modify This To Fit My Specific Needs?
Chances are this post did not give you the exact answer you were looking for. We all have different situations and it’s impossible to account for every particular need one might have. That’s why I want to share with you: My Guide to Getting the Solution to your Problems FAST! In this article, I explain the best strategies I have come up with over the years to get quick answers to complex problems in Excel, PowerPoint, VBA, you name it!
I highly recommend that you check this guide out before asking me or anyone else in the comments section to solve your specific problem. I can guarantee that 9 times out of 10, one of my strategies will get you the answer(s) you are needing faster than it will take me to get back to you with a possible solution. I try my best to help everyone out, but sometimes I don’t have time to fit everyone’s questions in (there never seem to be quite enough hours in the day!).
I wish you the best of luck and I hope this tutorial gets you heading in the right direction!
After 10+ years of creating macros and developing add-ins, I've compiled all the hacks I wish I had known years ago!
Excel VBA To Add Custom Colors To Recent Colors Section of Palette
A Little Background This post shows how you can use VBA code to add specific colors (outside your color theme)...
VBA Function To Determine If A Shape Has A Gradient Effect
What This VBA Code Does I recently needed to create a VBA function that tests if a particular shape object...
Chris is a finance professional and Excel MVP recognized by Microsoft since 2016. With his expertise, he founded TheSpreadsheetGuru blog to help fellow Excel users, where he shares his vast creative solutions & expertise. In addition, he has developed over 7 widely-used Excel Add-ins that have been embraced by individuals and companies worldwide.