{"id":16156,"date":"2023-08-08T10:49:40","date_gmt":"2023-08-08T10:49:40","guid":{"rendered":"https:\/\/officetuts.net\/excel\/?p=16156"},"modified":"2024-03-26T11:37:07","modified_gmt":"2024-03-26T11:37:07","slug":"count-merged-cells-in-excel","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/","title":{"rendered":"Count Merged Cells in Excel"},"content":{"rendered":"\n

In Excel, you can combine all the existing formulas with the data that you have. However, there are some limitations for which we need to use Visual Basic for Applications (VBA)<\/strong>. Such is the case with counting merged cells<\/strong>.<\/p>\n\n\n\n

In the example below, we will show how to do it.<\/p>\n\n\n\n

Count Merged Cells in Excel<\/h2>\n\n\n\n

For our example, we will use the sales results for January through March<\/strong>, and for different regions: North, East, West, and South<\/strong>:<\/p>\n\n\n\n

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

As seen from the table, all the months<\/strong>, and three regions: East, West, and South are merged<\/strong>. To merge the cells in the first place, we have to choose the cells to be merged, then go to the Home tab >> Alignment and choose any option from the Merge & Center dropdown<\/strong>:<\/p>\n\n\n\n

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

We already did this for our example. If we would want to count the number of cells in the range where merged cells are located (not including headers, we would usually try the following formula:<\/p>\n\n\n\n

=COUNT(A2:A11,C2:C11)<\/code><\/pre>\n\n\n\n

The result that we should have is 6<\/strong>, as the total number of merged areas is 6<\/strong>. When we type in the formula, the result will be 0<\/strong>, which is not true:<\/p>\n\n\n\n

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

To count the merged cells, we need to use VBA. We will open it by clicking ALT + F11<\/strong> on our keyboard. On the window that appears we will choose the Insert tab and then choose Module<\/strong>:<\/p>\n\n\n\n

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

In the window that appears, we will insert the following formula:<\/p>\n\n\n\n

Function CountMergedCells(pRng As Range) As Long\nDim r As Range\nDim total As Long\nSet j = CreateObject(\"Scripting.Dictionary\")\nFor Each r In pRng\n    If r.MergeCells Then\n        TempAddress = r.MergeArea.Address\n        j(TempAddress) = \"\"\n    End If\nNext\nCountMergedCells = j.Count\nEnd Function<\/code><\/pre>\n\n\n\n

VBA has a built-in feature to create formulas. In our code, we did just that. Our formula has one parameter<\/strong>, which is range<\/strong>. We first declare two variables, r as range and total as long (a number)<\/strong>. Then we set the j variable to create an object from the Scripting library<\/strong>.<\/p>\n\n\n\n

For the most important part of the code, we input the For Each Loop<\/strong> in which we declare that for every instance in our range where cells are merged, we declare the TempAddress <\/strong>which will be stored and counted in variable j<\/strong>.<\/p>\n\n\n\n

Then we define that the count of all the total merged cells is equal to our j variable<\/strong>.<\/p>\n\n\n\n

Since this is not a standard Macro, but a formula, we cannot call it by clicking F5<\/strong> on our keyboard. We will return to our Excel file, and simply call our formula by its name- CountMergedCells<\/strong>. The formula only has one parameter- range, and we will choose range A2:C11<\/strong>. Our formula (which we will insert in cell B15<\/strong>) will be:<\/p>\n\n\n\n

=CountMergedCells(A2:C11)<\/code><\/pre>\n\n\n\n

And our result will be 6<\/strong>:<\/p>\n\n\n\n

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

This is the result we were aiming for since we\u2019ve got January, February, March, East, West, and South merged in our range<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"

In Excel, you can combine all the existing formulas with the data that you have. However, there are some limitations for which we…<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[190],"yoast_head":"\nCount Merged Cells in Excel<\/title>\n<meta name=\"description\" content=\"Combine Excel formulas with VBA to count merged cells. Learn how to do it with a practical example.\" \/>\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\/examples\/count-merged-cells-in-excel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Count Merged Cells in Excel\" \/>\n<meta property=\"og:description\" content=\"Combine Excel formulas with VBA to count merged cells. Learn how to do it with a practical example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-08T10:49:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-26T11:37:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png\" \/>\n<meta name=\"author\" content=\"Harun Spahic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Harun Spahic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/\"},\"author\":{\"name\":\"Harun Spahic\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2\"},\"headline\":\"Count Merged Cells in Excel\",\"datePublished\":\"2023-08-08T10:49:40+00:00\",\"dateModified\":\"2024-03-26T11:37:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/\"},\"wordCount\":446,\"publisher\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png\",\"keywords\":[\"pinterest\"],\"articleSection\":[\"examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/\",\"url\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/\",\"name\":\"Count Merged Cells in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/officetuts.net\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png\",\"datePublished\":\"2023-08-08T10:49:40+00:00\",\"dateModified\":\"2024-03-26T11:37:07+00:00\",\"description\":\"Combine Excel formulas with VBA to count merged cells. Learn how to do it with a practical example.\",\"breadcrumb\":{\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage\",\"url\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png\",\"contentUrl\":\"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png\",\"width\":290,\"height\":290},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/officetuts.net\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Count Merged Cells in Excel\"}]},{\"@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.\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2\",\"name\":\"Harun Spahic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g\",\"caption\":\"Harun Spahic\"},\"sameAs\":[\"http:\/\/human.bsru.ac.th\/\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Count Merged Cells in Excel","description":"Combine Excel formulas with VBA to count merged cells. Learn how to do it with a practical example.","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\/examples\/count-merged-cells-in-excel\/","og_locale":"en_US","og_type":"article","og_title":"Count Merged Cells in Excel","og_description":"Combine Excel formulas with VBA to count merged cells. Learn how to do it with a practical example.","og_url":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/","article_published_time":"2023-08-08T10:49:40+00:00","article_modified_time":"2024-03-26T11:37:07+00:00","og_image":[{"url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png"}],"author":"Harun Spahic","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Harun Spahic","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#article","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/"},"author":{"name":"Harun Spahic","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2"},"headline":"Count Merged Cells in Excel","datePublished":"2023-08-08T10:49:40+00:00","dateModified":"2024-03-26T11:37:07+00:00","mainEntityOfPage":{"@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/"},"wordCount":446,"publisher":{"@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/41b0b6996aaa4c4127f86f3d24452d42"},"image":{"@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png","keywords":["pinterest"],"articleSection":["examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/","url":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/","name":"Count Merged Cells in Excel","isPartOf":{"@id":"https:\/\/officetuts.net\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage"},"image":{"@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage"},"thumbnailUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png","datePublished":"2023-08-08T10:49:40+00:00","dateModified":"2024-03-26T11:37:07+00:00","description":"Combine Excel formulas with VBA to count merged cells. Learn how to do it with a practical example.","breadcrumb":{"@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#primaryimage","url":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png","contentUrl":"https:\/\/officetuts.net\/excel\/wp-content\/uploads\/sites\/2\/2023\/08\/word-image-16156-1.png","width":290,"height":290},{"@type":"BreadcrumbList","@id":"https:\/\/officetuts.net\/excel\/examples\/count-merged-cells-in-excel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/officetuts.net\/excel\/"},{"@type":"ListItem","position":2,"name":"Count Merged Cells in Excel"}]},{"@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."},{"@type":"Person","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/694491c70f776081acdac4ae41f222a2","name":"Harun Spahic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/officetuts.net\/excel\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b7b887a2249679182be5550a4421a7a9?s=96&d=mm&r=g","caption":"Harun Spahic"},"sameAs":["http:\/\/human.bsru.ac.th\/"]}]}},"_links":{"self":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/16156"}],"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\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/comments?post=16156"}],"version-history":[{"count":1,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/16156\/revisions"}],"predecessor-version":[{"id":16162,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/posts\/16156\/revisions\/16162"}],"wp:attachment":[{"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/media?parent=16156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/categories?post=16156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/officetuts.net\/excel\/wp-json\/wp\/v2\/tags?post=16156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}