{"id":3114,"date":"2018-09-22T17:54:42","date_gmt":"2018-09-22T17:54:42","guid":{"rendered":"http:\/\/officetuts.net\/excel\/?p=3114"},"modified":"2024-03-30T00:19:17","modified_gmt":"2024-03-30T00:19:17","slug":"check-if-cell-is-empty","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/","title":{"rendered":"VBA Check if Cell is Empty"},"content":{"rendered":"\n

The simplest way in VBA to check whether the cell is empty is by using the IsEmpty<\/strong> function.<\/p>\n\n\n\n

Take a look at the following example.<\/p>\n\n\n\n

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

In column A you have some data. In cell A2<\/strong> you have space. The following code takes the active cell and displays a message window to show you which cell is empty.<\/p>\n\n\n\n

Sub CheckIfEmpty()\n    If IsEmpty(ActiveCell.Value) Then\n        MsgBox (\"Cell is empty\")\n    Else\n        MsgBox (\"Cell is not empty\")\n    End If\nEnd Sub<\/pre>\n\n\n\n

As you can see space is treated as not empty and formatting is treated as empty.<\/p>\n\n\n\n

Treat the space as an empty cell<\/h2>\n\n\n\n

It\u2019s quite likely that we want to treat space as an empty cell. This time we will write our code a little differently. We won\u2019t use the IsEmpty<\/strong> function.<\/p>\n\n\n\n

Sub CheckIfEmpty()\n    Dim check_if_empty As String\n    check_if_empty = Trim(ActiveCell.Value)\n    If check_if_empty = \"\" Then\n        MsgBox (\"Cell is empty\")\n    Else\n        MsgBox (\"Cell is not empty\")\n    End If\nEnd Sub<\/pre>\n\n\n\n

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

3.<\/strong> Trim(ActiveCell.Value) will remove multiple spaces from the beginning and end of the string. If there are only multiple spaces in a cell it will return \u201c\u201d.<\/p>\n\n\n\n

Sub CheckIfEmpty()\n    Dim check_if_empty As String\n    check_if_empty = Trim(ActiveCell.Value)\n    If check_if_empty = \"\" Then\n        MsgBox (\"Cell is empty\")\n    Else\n        MsgBox (\"Cell is not empty\")\n    End If\nEnd Sub<\/pre>\n\n\n\n

Now if you run the code you will get.<\/p>\n\n\n\n

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

Cell A2<\/strong> is empty.<\/p>\n\n\n\n

Cell A3<\/strong> has a single space.<\/p>\n\n\n\n

Cell A4<\/strong> has multiple spaces.<\/p>\n\n\n\n

Cell A5<\/strong> has applied formatting.<\/p>\n","protected":false},"excerpt":{"rendered":"

The simplest way in VBA to check whether the cell is empty is by using the IsEmpty function. Take a look at the…<\/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":"\nVBA Check if Cell is Empty<\/title>\n<meta name=\"description\" content=\"Learn how to check if a cell is empty in VBA with the IsEmpty function. Follow this example to display a message window to show which cell is empty.\" \/>\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-if-cell-is-empty\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"VBA Check if Cell is Empty\" \/>\n<meta property=\"og:description\" content=\"Learn how to check if a cell is empty in VBA with the IsEmpty function. Follow this example to display a message window to show which cell is empty.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-22T17:54:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-30T00:19:17+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.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-if-cell-is-empty\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/\"},\"author\":{\"name\":\"Tomasz Decker\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"headline\":\"VBA Check if Cell is Empty\",\"datePublished\":\"2018-09-22T17:54:42+00:00\",\"dateModified\":\"2024-03-30T00:19:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/\"},\"wordCount\":175,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png\",\"keywords\":[\"pinterest\"],\"articleSection\":[\"vba\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/\",\"url\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/\",\"name\":\"VBA Check if Cell is Empty\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png\",\"datePublished\":\"2018-09-22T17:54:42+00:00\",\"dateModified\":\"2024-03-30T00:19:17+00:00\",\"description\":\"Learn how to check if a cell is empty in VBA with the IsEmpty function. Follow this example to display a message window to show which cell is empty.\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage\",\"url\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png\",\"contentUrl\":\"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"VBA Check if Cell is Empty\"}]},{\"@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":"VBA Check if Cell is Empty","description":"Learn how to check if a cell is empty in VBA with the IsEmpty function. Follow this example to display a message window to show which cell is empty.","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-if-cell-is-empty\/","og_locale":"en_US","og_type":"article","og_title":"VBA Check if Cell is Empty","og_description":"Learn how to check if a cell is empty in VBA with the IsEmpty function. Follow this example to display a message window to show which cell is empty.","og_url":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/","article_published_time":"2018-09-22T17:54:42+00:00","article_modified_time":"2024-03-30T00:19:17+00:00","og_image":[{"url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.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-if-cell-is-empty\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/"},"author":{"name":"Tomasz Decker","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"headline":"VBA Check if Cell is Empty","datePublished":"2018-09-22T17:54:42+00:00","dateModified":"2024-03-30T00:19:17+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/"},"wordCount":175,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png","keywords":["pinterest"],"articleSection":["vba"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/","url":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/","name":"VBA Check if Cell is Empty","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage"},"thumbnailUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png","datePublished":"2018-09-22T17:54:42+00:00","dateModified":"2024-03-30T00:19:17+00:00","description":"Learn how to check if a cell is empty in VBA with the IsEmpty function. Follow this example to display a message window to show which cell is empty.","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#primaryimage","url":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png","contentUrl":"http:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2018\/09\/empty-example.png"},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/vba\/check-if-cell-is-empty\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"VBA Check if Cell is Empty"}]},{"@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\/3114"}],"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=3114"}],"version-history":[{"count":4,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/3114\/revisions"}],"predecessor-version":[{"id":12945,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/3114\/revisions\/12945"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=3114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=3114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=3114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}