{"id":3183,"date":"2018-10-11T07:55:53","date_gmt":"2018-10-11T07:55:53","guid":{"rendered":"http:\/\/officetuts.net\/excel\/?p=3183"},"modified":"2024-03-29T15:55:39","modified_gmt":"2024-03-29T15:55:39","slug":"check-cell-color","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/","title":{"rendered":"Check Cell Color in VBA"},"content":{"rendered":"\n

Each color in Excel has its index. You can get both background and font color with a shortcode. Let\u2019s use the following example to illustrate how the code works.<\/p>\n\n\n\n

Example<\/h2>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Check cell background-color<\/h2>\n\n\n\n

In order to check the cell background color<\/a>, you have to use VBA. Press Alt + F11<\/strong> to open VBA Editor. Insert a new module into the project.<\/p>\n\n\n\n

We will use this function to determine the background color<\/a>.<\/p>\n\n\n\n

Function CheckBackgroundColor(cell As Range)\n    If (cell.Cells.Count > 1) Then\n        CheckBackgroundColor = \"Enter one cell\"\n        Exit Function\n    Else\n        CheckBackgroundColor = cell.Interior.Color\n    End If\nEnd Function<\/code><\/pre>\n\n\n\n

code explanation<\/strong><\/p>\n\n\n\n

The following function checks whether the range parameter is only a single cell. If it\u2019s not, it will display a text informing you to enter a single cell as a parameter.<\/p>\n\n\n\n

If you entered a single cell, the function displays its background color.<\/p>\n\n\n\n

Check cell font color<\/h2>\n\n\n\n

You can quickly modify this function to work also with font color<\/a>.<\/p>\n\n\n\n

Function CheckFontColor(cell As Range)\n    If (cell.Cells.Count > 1) Then\n        CheckFontColor = \"Enter one cell\"\n        Exit Function\n    Else\n        CheckFontColor = cell.Font.Color\n    End If\nEnd Function<\/code><\/pre>\n\n\n\n

This will give us the following result.<\/p>\n\n\n\n

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

What you get is a color in decimal form. You may want to convert them into hexadecimal form.<\/p>\n\n\n\n

=DEC2HEX(C2)<\/code><\/pre>\n\n\n\n

If you use it for the white text you will get FFFFFF<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"

Each color in Excel has its index. You can get both background and font color with a shortcode. Let\u2019s use the following example…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[190],"yoast_head":"\nCheck Cell Color in VBA<\/title>\n<meta name=\"description\" content=\"Learn how to check cell background and font color in Excel using VBA. Use a simple function to determine the color index with this step-by-step guide.\" \/>\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\/check-cell-color\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Check Cell Color in VBA\" \/>\n<meta property=\"og:description\" content=\"Learn how to check cell background and font color in Excel using VBA. Use a simple function to determine the color index with this step-by-step guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-11T07:55:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-29T15:55:39+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-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\/check-cell-color\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/\"},\"author\":{\"name\":\"Tomasz Decker\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"headline\":\"Check Cell Color in VBA\",\"datePublished\":\"2018-10-11T07:55:53+00:00\",\"dateModified\":\"2024-03-29T15:55:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/\"},\"wordCount\":175,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png\",\"keywords\":[\"pinterest\"],\"articleSection\":[\"vba\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/\",\"url\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/\",\"name\":\"Check Cell Color in VBA\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png\",\"datePublished\":\"2018-10-11T07:55:53+00:00\",\"dateModified\":\"2024-03-29T15:55:39+00:00\",\"description\":\"Learn how to check cell background and font color in Excel using VBA. Use a simple function to determine the color index with this step-by-step guide.\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage\",\"url\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png\",\"contentUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Check Cell Color in VBA\"}]},{\"@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":"Check Cell Color in VBA","description":"Learn how to check cell background and font color in Excel using VBA. Use a simple function to determine the color index with this step-by-step guide.","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\/check-cell-color\/","og_locale":"en_US","og_type":"article","og_title":"Check Cell Color in VBA","og_description":"Learn how to check cell background and font color in Excel using VBA. Use a simple function to determine the color index with this step-by-step guide.","og_url":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/","article_published_time":"2018-10-11T07:55:53+00:00","article_modified_time":"2024-03-29T15:55:39+00:00","og_image":[{"url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-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\/check-cell-color\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/"},"author":{"name":"Tomasz Decker","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"headline":"Check Cell Color in VBA","datePublished":"2018-10-11T07:55:53+00:00","dateModified":"2024-03-29T15:55:39+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/"},"wordCount":175,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png","keywords":["pinterest"],"articleSection":["vba"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/","url":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/","name":"Check Cell Color in VBA","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png","datePublished":"2018-10-11T07:55:53+00:00","dateModified":"2024-03-29T15:55:39+00:00","description":"Learn how to check cell background and font color in Excel using VBA. Use a simple function to determine the color index with this step-by-step guide.","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#primaryimage","url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png","contentUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/10\/cell-colors.png"},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/vba\/check-cell-color\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"Check Cell Color in VBA"}]},{"@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\/3183"}],"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=3183"}],"version-history":[{"count":8,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/3183\/revisions"}],"predecessor-version":[{"id":11591,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/3183\/revisions\/11591"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=3183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=3183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=3183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}