Dedicated cell color fill buttons - Excel 2013

I color code cells quite often, and would like to customize my ribbon so that I have a dedicated button for each of the colors I use most often, which are usually green, yellow and red. The Fill button allows you to maintain a preference for just one color at a time, which is OK if you only use one color, but can be a nuisance if you have to switch colors often.

I suspect that a solution could easily be having some snippets of VBA code available that take the current selection and paint it with a color that is hard-coded in the script, then linking the code to custom-made buttons that are made available to any and all spreadsheets that I open. (I haven't written anything in VBA for a while, so figuring this out on my own would take me quite a bit, I'm afraid)

Please note that I'm not referring to using conditional formatting - that I use often under some circumstances, but the cells I usually paint would depend on business rules that are rather complex to define.

April 10th, 2015 9:42am

The personal macro workbook Personal.xlsb is a handy place to store macros that you want to be available in all workbooks.

This workbook initially doesn't exist. You have to create it by recording a macro in it. See How do I create and use a PERSONAL file for my VBA code for detailed instructions.

Once you have created Personal.xlsb, copy the following macro code into a module in this workbook:

Sub FillGreen()
    On Error Resume Next
    Selection.Interior.Color = vbGreen
End Sub

Sub FillRed()
    On Error Resume Next
    Selection.Interior.Color = vbRed
End Sub

Sub FillYellow()
    On Error Resume Next
    Selection.Interior.Color = vbYellow
End Sub

Switch back to Excel. You can now assign the macros to custom buttons on your Quick Access Toolbar (QAT):

Click the dropdown arrow on the right hand side of the QAT.

Select More Commands... from the dropdown menu.

Select Macros from the "Choose commands from" dropdown.

Select PERSONAL.XLSB!FillGreen in the list of macros and click Add >>.

With the macro still selected in the list on the right hand side, click Modify...

Select a suitable icon (for example the green square) and enter a user-friendly display name, then click OK.

Do the same for the other two macros.

Free Windows Admin Tool Kit Click here and download it now
April 10th, 2015 10:27am

Excellent answer. Only thing missing was: "Close and reopen Excel" just after the code box, so that PERSONAL.xslb reloads and the macros are available to the QAT command list. :-)  Thanks a lot!
April 10th, 2015 1:49pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics