{"id":904,"date":"2020-11-25T16:29:01","date_gmt":"2020-11-25T16:29:01","guid":{"rendered":"http:\/\/www.vbastring.com\/blog\/?p=904"},"modified":"2020-11-27T17:55:17","modified_gmt":"2020-11-27T17:55:17","slug":"checking-if-month-changed-excel-vba-old-value-cell-target","status":"publish","type":"post","link":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/","title":{"rendered":"Checking If Month Changed &#8211; Excel VBA Old Value Cell Target"},"content":{"rendered":"<p> In response to a comment on my Youtube video:<\/p>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=Z9kt86I_rq0&#038;feature=em-comments\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/www.youtube.com\/watch?v=Z9kt86I_rq0&#038;feature=em-comments<\/a><\/p>\n<p>*This gives an example of how to get notified of a change made to one of the worksheet cells.<\/p>\n<pre class=\"lang:vb decode:true \" >Private Sub Worksheet_Change(ByVal Target As Range)\r\n    \r\n    Static blnDoneThis As Boolean\r\n    Dim varOldValue As Variant\r\n    Dim varNewValue As Variant\r\n    \r\n    'initialize a variable to regulate the Worksheet_Change event\r\n    If blnDoneThis Then\r\n        blnDoneThis = False\r\n        Exit Sub\r\n    End If\r\n    \r\n    'get the new value\r\n    varNewValue = Target.Value\r\n    \r\n    'set our regulator to true\r\n    blnDoneThis = True\r\n    \r\n    'time to get the old value and store it in a variable\r\n    Application.Undo\r\n\r\n    varOldValue = Target.Value\r\n    \r\n    'tell the regulator, it's ok\r\n    blnDoneThis = True\r\n    \r\n    'check if the month has changed from the old value\r\n    If Month(varNewValue) &lt;&gt; Month(varOldValue) Then\r\n        MsgBox \" Month has changed\"\r\n    End If\r\n    \r\n    'set the cell equal to the new value\r\n    Target.Value = varNewValue\r\n    \r\n    \r\nEnd Sub<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In response to a comment on my Youtube video: https:\/\/www.youtube.com\/watch?v=Z9kt86I_rq0&#038;feature=em-comments *This gives an example of how to get notified of a change made to one of the worksheet cells. Private Sub Worksheet_Change(ByVal Target As Range) Static blnDoneThis As Boolean Dim varOldValue As Variant Dim varNewValue As Variant &#8216;initialize a variable to regulate the Worksheet_Change event [&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-904","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>Checking If Month Changed - Excel VBA Old Value Cell Target - 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\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Checking If Month Changed - Excel VBA Old Value Cell Target - My Blog\" \/>\n<meta property=\"og:description\" content=\"In response to a comment on my Youtube video: https:\/\/www.youtube.com\/watch?v=Z9kt86I_rq0&#038;feature=em-comments *This gives an example of how to get notified of a change made to one of the worksheet cells. Private Sub Worksheet_Change(ByVal Target As Range) Static blnDoneThis As Boolean Dim varOldValue As Variant Dim varNewValue As Variant &#039;initialize a variable to regulate the Worksheet_Change event [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/\" \/>\n<meta property=\"og:site_name\" content=\"My Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-25T16:29:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-27T17:55:17+00:00\" \/>\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\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"headline\":\"Checking If Month Changed &#8211; Excel VBA Old Value Cell Target\",\"datePublished\":\"2020-11-25T16:29:01+00:00\",\"dateModified\":\"2020-11-27T17:55:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/\"},\"wordCount\":51,\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/\",\"url\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/\",\"name\":\"Checking If Month Changed - Excel VBA Old Value Cell Target - My Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#website\"},\"datePublished\":\"2020-11-25T16:29:01+00:00\",\"dateModified\":\"2020-11-27T17:55:17+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/#\\\/schema\\\/person\\\/e1de0b30e98940381697872449c341f5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/2020\\\/11\\\/25\\\/checking-if-month-changed-excel-vba-old-value-cell-target\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vbastring.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Checking If Month Changed &#8211; Excel VBA Old Value Cell Target\"}]},{\"@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":"Checking If Month Changed - Excel VBA Old Value Cell Target - 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\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/","og_locale":"en_US","og_type":"article","og_title":"Checking If Month Changed - Excel VBA Old Value Cell Target - My Blog","og_description":"In response to a comment on my Youtube video: https:\/\/www.youtube.com\/watch?v=Z9kt86I_rq0&#038;feature=em-comments *This gives an example of how to get notified of a change made to one of the worksheet cells. Private Sub Worksheet_Change(ByVal Target As Range) Static blnDoneThis As Boolean Dim varOldValue As Variant Dim varNewValue As Variant 'initialize a variable to regulate the Worksheet_Change event [&hellip;]","og_url":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/","og_site_name":"My Blog","article_published_time":"2020-11-25T16:29:01+00:00","article_modified_time":"2020-11-27T17:55:17+00:00","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\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/#article","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/"},"author":{"name":"admin","@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"headline":"Checking If Month Changed &#8211; Excel VBA Old Value Cell Target","datePublished":"2020-11-25T16:29:01+00:00","dateModified":"2020-11-27T17:55:17+00:00","mainEntityOfPage":{"@id":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/"},"wordCount":51,"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/","url":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/","name":"Checking If Month Changed - Excel VBA Old Value Cell Target - My Blog","isPartOf":{"@id":"https:\/\/vbastring.com\/blog\/#website"},"datePublished":"2020-11-25T16:29:01+00:00","dateModified":"2020-11-27T17:55:17+00:00","author":{"@id":"https:\/\/vbastring.com\/blog\/#\/schema\/person\/e1de0b30e98940381697872449c341f5"},"breadcrumb":{"@id":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vbastring.com\/blog\/2020\/11\/25\/checking-if-month-changed-excel-vba-old-value-cell-target\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vbastring.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Checking If Month Changed &#8211; Excel VBA Old Value Cell Target"}]},{"@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\/904","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=904"}],"version-history":[{"count":2,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/904\/revisions"}],"predecessor-version":[{"id":910,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/posts\/904\/revisions\/910"}],"wp:attachment":[{"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/media?parent=904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/categories?post=904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vbastring.com\/blog\/wp-json\/wp\/v2\/tags?post=904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}