{"id":4768,"date":"2019-11-11T08:58:56","date_gmt":"2019-11-11T08:58:56","guid":{"rendered":"http:\/\/officetuts.net\/excel\/?p=4768"},"modified":"2024-03-30T11:08:50","modified_gmt":"2024-03-30T11:08:50","slug":"conditional-formatting-based-on-cell-color","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/","title":{"rendered":"Conditional Formatting Based on Cell Color"},"content":{"rendered":"\n

If you want to use conditional formatting where a criterion\nis a cell color, you can’t just use standard conditional formatting. You have\nto create a VBA function that will recognize color and apply adequate\nformatting.<\/p>\n\n\n\n

In this tutorial, we are going to create a formula that will\nname a color based on the cell<\/a> background.<\/p>\n\n\n\n

Let’s take standard colors from the Excel palette. You can find them in Home >> Font >> Fill Color >> Standard Colors<\/strong>.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Let’s display them inside cells, from A2<\/strong> to A11<\/strong>.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Now, let’s create a function that will identify colors. Open\nthe VBA window by pressing Left Alt +\nF11<\/strong>.<\/p>\n\n\n\n

Create a new module: right-click project >> Insert >> Class Module<\/strong>.<\/p>\n\n\n\n

Function CellBackgroundColor(rng As Range) As String\n    For Each elem In rng\n        CellBackgroundColor = elem.Interior.Color\n    Next elem\nEnd Function<\/code><\/pre>\n\n\n\n

Start typing the function name inside column B2<\/strong> and AutoFill<\/a> the rest of the cells.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

These numbers don’t tell us much. Let’s modify our function to apply names to these colors.<\/p>\n\n\n\n

Function CellBackgroundColor(rng As Range) As String\n    For Each elem In rng\n        Select Case elem.Interior.Color\n            Case Is = 192\n                CellBackgroundColor = \"Dark Red\"\n            Case Is = 255\n                CellBackgroundColor = \"Red\"\n            Case Is = 49407\n                CellBackgroundColor = \"Orange\"\n            Case Is = 65535\n                CellBackgroundColor = \"Yellow\"\n            Case Is = 5296274\n                CellBackgroundColor = \"Light Green\"\n            Case Is = 5287936\n                CellBackgroundColor = \"Green\"\n            Case Is = 15773696\n                CellBackgroundColor = \"Light Blue\"\n            Case Is = 12611584\n                CellBackgroundColor = \"Blue\"\n            Case Is = 6299648\n                CellBackgroundColor = \"Dark Blue\"\n            Case Is = 10498160\n                CellBackgroundColor = \"Purple\"\n        End Select\n    Next elem\nEnd Function<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

If you want to use conditional formatting where a criterion is a cell color, you can’t just use standard conditional formatting. You have…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[190],"yoast_head":"\nConditional Formatting Based on Cell Color<\/title>\n<meta name=\"description\" content=\"Learn how to create a VBA function to recognize cell color and apply proper formatting using this Excel tutorial. Name colors based on cell backgrounds.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Conditional Formatting Based on Cell Color\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a VBA function to recognize cell color and apply proper formatting using this Excel tutorial. Name colors based on cell backgrounds.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-11T08:58:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-30T11:08:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png\" \/>\n<meta name=\"author\" content=\"Tomasz Decker\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tomasz Decker\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/\"},\"author\":{\"name\":\"Tomasz Decker\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"headline\":\"Conditional Formatting Based on Cell Color\",\"datePublished\":\"2019-11-11T08:58:56+00:00\",\"dateModified\":\"2024-03-30T11:08:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/\"},\"wordCount\":164,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png\",\"keywords\":[\"pinterest\"],\"articleSection\":[\"vba\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/\",\"url\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/\",\"name\":\"Conditional Formatting Based on Cell Color\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png\",\"datePublished\":\"2019-11-11T08:58:56+00:00\",\"dateModified\":\"2024-03-30T11:08:50+00:00\",\"description\":\"Learn how to create a VBA function to recognize cell color and apply proper formatting using this Excel tutorial. Name colors based on cell backgrounds.\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage\",\"url\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png\",\"contentUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png\",\"width\":438,\"height\":299},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Conditional Formatting Based on Cell Color\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/officetuts.net\/excel\/#website\",\"url\":\"https:\/\/officetuts.net\/excel\/\",\"name\":\"\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/officetuts.net\/excel\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\",\"name\":\"Tomasz Decker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g\",\"caption\":\"Tomasz Decker\"},\"logo\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\"},\"description\":\"Spreadsheet and Python enthusiast.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Conditional Formatting Based on Cell Color","description":"Learn how to create a VBA function to recognize cell color and apply proper formatting using this Excel tutorial. Name colors based on cell backgrounds.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/","og_locale":"en_US","og_type":"article","og_title":"Conditional Formatting Based on Cell Color","og_description":"Learn how to create a VBA function to recognize cell color and apply proper formatting using this Excel tutorial. Name colors based on cell backgrounds.","og_url":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/","article_published_time":"2019-11-11T08:58:56+00:00","article_modified_time":"2024-03-30T11:08:50+00:00","og_image":[{"url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png"}],"author":"Tomasz Decker","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Tomasz Decker","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/"},"author":{"name":"Tomasz Decker","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"headline":"Conditional Formatting Based on Cell Color","datePublished":"2019-11-11T08:58:56+00:00","dateModified":"2024-03-30T11:08:50+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/"},"wordCount":164,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png","keywords":["pinterest"],"articleSection":["vba"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/","url":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/","name":"Conditional Formatting Based on Cell Color","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png","datePublished":"2019-11-11T08:58:56+00:00","dateModified":"2024-03-30T11:08:50+00:00","description":"Learn how to create a VBA function to recognize cell color and apply proper formatting using this Excel tutorial. Name colors based on cell backgrounds.","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#primaryimage","url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png","contentUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2019\/11\/standard-colors.png","width":438,"height":299},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/vba\/conditional-formatting-based-on-cell-color\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"Conditional Formatting Based on Cell Color"}]},{"@type":"WebSite","@id":"https:\/\/officetuts.net\/excel\/#website","url":"https:\/\/officetuts.net\/excel\/","name":"","description":"","publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/officetuts.net\/excel\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42","name":"Tomasz Decker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/18cbe22837193574870ae40ba56bf712?s=96&d=mm&r=g","caption":"Tomasz Decker"},"logo":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/"},"description":"Spreadsheet and Python enthusiast."}]}},"_links":{"self":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/4768"}],"collection":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/comments?post=4768"}],"version-history":[{"count":5,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/4768\/revisions"}],"predecessor-version":[{"id":12961,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/4768\/revisions\/12961"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=4768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=4768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=4768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}