{"id":659,"date":"2012-07-09T14:53:51","date_gmt":"2012-07-09T14:53:51","guid":{"rendered":"http:\/\/www.geoplanit.co.uk\/?p=659"},"modified":"2012-07-09T14:53:51","modified_gmt":"2012-07-09T14:53:51","slug":"excel-macro-convert-cell-fill-colour-to-hexadecimal-code","status":"publish","type":"post","link":"https:\/\/www.geoplanit.co.uk\/?p=659","title":{"rendered":"Excel Macro &#8211; Convert Cell Fill Colour to Hexadecimal Code"},"content":{"rendered":"<p>Exciting code being posted today I know, this is related to a previous post (<a href=\"http:\/\/www.geoplanit.co.uk\/?p=635\">CityEngine rule creation using Excel<\/a>) but could come in use in other projects that use\u00a0hexadecimal\u00a0colour codes&#8230;<\/p>\n<p>First create a new macro called &#8220;ConvertToHex&#8221; and use the following code:<\/p>\n<p>&nbsp;<\/p>\n<pre>Application.ScreenUpdating = False\r\nApplication.Calculation = xlCalculationManual\r\nDim str0 As String, str As String\r\nDim cel As Range\r\nFor Each cel In Selection\r\nstr0 = Right(\"000000\" &amp; Hex(cel.Interior.Color), 6)\r\nstr = Right(str0, 2) &amp; Mid(str0, 3, 2) &amp; Left(str0, 2)\r\ncel = \"#\" &amp; str &amp; \"\"\r\nNext cel\r\ndone:\r\nApplication.Calculation = xlCalculationAutomatic\r\nApplication.ScreenUpdating = True<\/pre>\n<p>Customize your toolbar and add this macro as a button, then select a cell and change its fill colour, then making sure you&#8217;ve still selected the colour cell press the macro button or run this macro, voila it should write in the cell it&#8217;s hexvalue!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Exciting code being posted today I know, this is related to a previous post (CityEngine rule creation using Excel) but could come in use in other projects that use\u00a0hexadecimal\u00a0colour codes&#8230; First create a new macro called &#8220;ConvertToHex&#8221; and use the following code: &nbsp; Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Dim str0 As String, str As [&hellip;]<\/p>\n","protected":false},"author":161,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145,32,91,54],"tags":[],"class_list":["post-659","post","type-post","status-publish","format-standard","category-cityengine","category-excel","category-programming","category-tips"],"_links":{"self":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/users\/161"}],"replies":[{"embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=659"}],"version-history":[{"count":2,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/659\/revisions"}],"predecessor-version":[{"id":661,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/659\/revisions\/661"}],"wp:attachment":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}