{"id":5953,"date":"2020-02-05T20:49:30","date_gmt":"2020-02-06T01:49:30","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=5953"},"modified":"2020-02-06T12:50:19","modified_gmt":"2020-02-06T17:50:19","slug":"excel-setting-a-cell-value-based-on-background-color","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=5953","title":{"rendered":"Excel \u2013 Setting a Cell Value Based on Background Color"},"content":{"rendered":"<p>I need to programmatically parse an Excel file where items are grouped with arbitrary group sizes. We <em>don&#8217;t<\/em> want the person filling out the spreadsheet to need to fill in a group # column &#8230; so I&#8217;m exploring ways to read cell formatting so something like color can be used to show the groups. Reading the formatting isn&#8217;t a straight-forward process, so I wondered if Excel could populate a group number cell based on the cell&#8217;s attributes.<\/p>\n<p>While it is possible, it&#8217;s not a viable solution. The mechanism to access data about a cell cannot be accessed directly and, unfortunately, requires a macro-enabled workbook. The mechanism also requires the user to remember to update the spreadsheet calculations when they have finished colorizing the rows. While I won&#8217;t be using this approach in my current project &#8230; I thought I&#8217;d record what I did for future reference.<\/p>\n<p>We need to define a \u2018name\u2019 for the function. On the \u201cFormulas\u201d tab, select \u201cName Manager\u201d.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"193\" class=\"wp-image-5954\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image.png 815w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-300x71.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-768x182.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-750x178.png 750w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/p>\n<p>Select \u2018New\u2019<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"363\" height=\"77\" class=\"wp-image-5955\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-1.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-1.png 363w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-1-300x64.png 300w\" sizes=\"auto, (max-width: 363px) 100vw, 363px\" \/><\/p>\n<p>Provide a name \u2013 I am using getBackgroundColor \u2013 and put the following in the \u201crefers to\u201d section: =GET.CELL(63,INDIRECT(&#8220;rc&#8221;,FALSE))<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"302\" height=\"232\" class=\"wp-image-5956\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-2.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-2.png 302w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-2-300x230.png 300w\" sizes=\"auto, (max-width: 302px) 100vw, 302px\" \/><\/p>\n<p>Now we can use this name within the cell formula:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"338\" class=\"wp-image-5957\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-3.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-3.png 528w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-3-300x192.png 300w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/p>\n<p>Select the rows for your first group and change the \u201cfill color\u201d of the row.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"610\" height=\"385\" class=\"wp-image-5958\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-4.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-4.png 610w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-4-300x189.png 300w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p>Repeat this process to colorize all of your groups \u2013 you can re-use a color as long as adjacent groups have different colors. Notice that the \u201cColorGroup\u201d values do not change when you colorize your groups.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"490\" height=\"197\" class=\"wp-image-5959\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-5.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-5.png 490w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-5-300x121.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/p>\n<p>On the \u201cForumlas\u201d tab, select \u201cCalculate Now\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1295\" height=\"191\" class=\"wp-image-5960\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-6.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-6.png 1295w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-6-300x44.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-6-1024x151.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-6-768x113.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-6-750x111.png 750w\" sizes=\"auto, (max-width: 1295px) 100vw, 1295px\" \/><\/p>\n<p>Now the colorized cells will have a non-zero value.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"537\" height=\"481\" class=\"wp-image-5961\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-7.png\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-7.png 537w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2020\/02\/word-image-7-300x269.png 300w\" sizes=\"auto, (max-width: 537px) 100vw, 537px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I need to programmatically parse an Excel file where items are grouped with arbitrary group sizes. We don&#8217;t want the person filling out the spreadsheet to need to fill in a group # column &#8230; so I&#8217;m exploring ways to read cell formatting so something like color can be used to show the groups. Reading &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[677],"tags":[708,710,709,691,729,731,265],"class_list":["post-5953","post","type-post","status-publish","format-standard","hentry","category-office-365","tag-excel","tag-excel-functions","tag-microsoft-excel","tag-microsoft-office","tag-microsoft-office-365","tag-ms-excel","tag-office-365"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5953"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5953\/revisions"}],"predecessor-version":[{"id":5962,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5953\/revisions\/5962"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}