{"id":565,"date":"2019-02-23T21:42:58","date_gmt":"2019-02-23T21:42:58","guid":{"rendered":"http:\/\/www.vbastring.com\/blog\/?p=565"},"modified":"2019-02-23T21:44:25","modified_gmt":"2019-02-23T21:44:25","slug":"how-use-vba-to-evaluate-two-cells","status":"publish","type":"post","link":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/","title":{"rendered":"How Use VBA To Evaluate Two Cells"},"content":{"rendered":"<p>This post is actually a response to a question someone had.  <\/p>\n<blockquote><p>\u202ai need help comparing two cells with a high and low value, one of the cells is blue. Return 1 if the lowest value is blue color or return zero if the higher value is blue color. how do i perform this task in excel?\u202c\ufeff<\/p><\/blockquote>\n<p>Here in this example we have 2 columns:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png?resize=174%2C300\" alt=\"\" width=\"174\" height=\"300\" class=\"alignleft size-medium wp-image-566\" \/><\/a><\/p>\n<p>In order to evaluate the 2 columns, it&#8217;s best to generate a user defined function.<\/p>\n<p><strong>This is the code for the user defined function (in a module):<\/strong><\/p>\n<pre class=\"lang:vb decode:true \" >Public Function EvaluateCellContents(Row) As Integer\r\n    Dim intResult As Integer\r\n    Dim intRow As Integer\r\n    \r\n    Dim strBlue As String\r\n    Dim strBlack As String\r\n    \r\n    strBlue = 13998939\r\n    strBlack = 0\r\n        \r\n    intRow = Row\r\n    \r\n    intResult = 0\r\n    \r\n    'DOES RANGE A HAS A BLUE FONT COLOR?\r\n    If Range(\"A\" &amp; intRow).Font.Color = strBlue Then\r\n        'IS THE BLUE VALUE LOWER?\r\n        If Range(\"A\" &amp; intRow) &lt; Range(\"B\" &amp; intRow) Then\r\n            intResult = 1\r\n        Else\r\n            intResult = 0\r\n        End If\r\n    End If\r\n    \r\n    'DOES RANGE B HAS A BLUE FONT COLOR?\r\n    If Range(\"B\" &amp; intRow).Font.Color = strBlue Then\r\n        'IS THE BLUE VALUE LOWER?\r\n        If Range(\"B\" &amp; intRow) &lt; Range(\"A\" &amp; intRow) Then\r\n            intResult = 1\r\n        Else\r\n            intResult = 0\r\n        End If\r\n    End If\r\n    \r\n    \r\n    EvaluateCellContents = intResult\r\n    \r\nEnd Function\r\n<\/pre>\n<p>This is the way to call it from the worksheet:<\/p>\n<p><em><strong>=EvaluateCellContents((ROW(A4)))<\/strong><\/em><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells1.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells1-296x300.png?resize=296%2C300\" alt=\"\" width=\"296\" height=\"300\" class=\"alignleft size-medium wp-image-569\" \/><\/a><\/p>\n<p><\/p>\n<p>and here is the end result:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells2.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells2-211x300.png?resize=211%2C300\" alt=\"\" width=\"211\" height=\"300\" class=\"alignleft size-medium wp-image-570\" \/><\/a><\/p>\n<p>Let me know if you have any questions.<\/p>\n<p>****************************************************<\/p>\n<table border=\"1\" width=\"100%\">\n<tr>\n<td align=\"middle\">\n<div class=\"AW-Form-1094354588\"><\/div>\n<p><script type=\"text\/javascript\">(function(d, s, id) {\n    var js, fjs = d.getElementsByTagName(s)[0];\n    if (d.getElementById(id)) return;\n    js = d.createElement(s); js.id = id;\n    js.src = \"\/\/forms.aweber.com\/form\/88\/1094354588.js\";\n    fjs.parentNode.insertBefore(js, fjs);\n    }(document, \"script\", \"aweber-wjs-kkrwj13ov\"));\n<\/script>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>This post is actually a response to a question someone had. \u202ai need help comparing two cells with a high and low value, one of the cells is blue. Return 1 if the lowest value is blue color or return zero if the higher value is blue color. how do i perform this task in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-565","post","type-post","status-publish","format-standard","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How Use VBA To Evaluate Two Cells - My Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Use VBA To Evaluate Two Cells - My Blog\" \/>\n<meta property=\"og:description\" content=\"This post is actually a response to a question someone had. \u202ai need help comparing two cells with a high and low value, one of the cells is blue. Return 1 if the lowest value is blue color or return zero if the higher value is blue color. how do i perform this task in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/\" \/>\n<meta property=\"og:site_name\" content=\"My Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-23T21:42:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-23T21:44:25+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\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:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"headline\":\"How Use VBA To Evaluate Two Cells\",\"datePublished\":\"2019-02-23T21:42:58+00:00\",\"dateModified\":\"2019-02-23T21:44:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/\"},\"wordCount\":123,\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/\",\"name\":\"How Use VBA To Evaluate Two Cells - My Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png\",\"datePublished\":\"2019-02-23T21:42:58+00:00\",\"dateModified\":\"2019-02-23T21:44:25+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png\",\"contentUrl\":\"http:\\\/\\\/www.vbastring.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/02\\\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2019\\\/02\\\/23\\\/how-use-vba-to-evaluate-two-cells\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Use VBA To Evaluate Two Cells\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\",\"name\":\"My Blog\",\"description\":\"My WordPress Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/vbastring.com\\\/blog\"],\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How Use VBA To Evaluate Two Cells - My Blog","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:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/","og_locale":"en_US","og_type":"article","og_title":"How Use VBA To Evaluate Two Cells - My Blog","og_description":"This post is actually a response to a question someone had. \u202ai need help comparing two cells with a high and low value, one of the cells is blue. Return 1 if the lowest value is blue color or return zero if the higher value is blue color. how do i perform this task in [&hellip;]","og_url":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/","og_site_name":"My Blog","article_published_time":"2019-02-23T21:42:58+00:00","article_modified_time":"2019-02-23T21:44:25+00:00","og_image":[{"url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/#article","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/"},"author":{"name":"admin","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"headline":"How Use VBA To Evaluate Two Cells","datePublished":"2019-02-23T21:42:58+00:00","dateModified":"2019-02-23T21:44:25+00:00","mainEntityOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/"},"wordCount":123,"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/","url":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/","name":"How Use VBA To Evaluate Two Cells - My Blog","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/#primaryimage"},"image":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png","datePublished":"2019-02-23T21:42:58+00:00","dateModified":"2019-02-23T21:44:25+00:00","author":{"@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"breadcrumb":{"@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/#primaryimage","url":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png","contentUrl":"http:\/\/www.vbastring.com\/blog\/wp-content\/uploads\/2019\/02\/How-Use-VBA-To-Evaluate-Two-Cells-174x300.png"},{"@type":"BreadcrumbList","@id":"https:\/\/vbastring.com\/blog\/2019\/02\/23\/how-use-vba-to-evaluate-two-cells\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vbastring.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How Use VBA To Evaluate Two Cells"}]},{"@type":"WebSite","@id":"https:\/\/vbastring.com\/blog\/#website","url":"https:\/\/vbastring.com\/blog\/","name":"My Blog","description":"My WordPress Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vbastring.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b2feaa698a4bd91b409df1beb5ff6acc2d7842d4f78543d413ebd468bc0171af?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/vbastring.com\/blog"],"url":"https:\/\/vbastring.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/comments?post=565"}],"version-history":[{"count":4,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/565\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/565\/revisions\/576"}],"wp:attachment":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/media?parent=565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/categories?post=565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/tags?post=565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}