{"id":861,"date":"2016-08-01T23:37:34","date_gmt":"2016-08-02T03:37:34","guid":{"rendered":"http:\/\/regina-whipp.com\/blog\/?p=861"},"modified":"2018-07-18T22:37:18","modified_gmt":"2018-07-19T02:37:18","slug":"hide-duplicate-rows-in-excel","status":"publish","type":"post","link":"https:\/\/regina-whipp.com\/blog\/?p=861","title":{"rendered":"Hide Duplicate Rows in Excel&#8230;"},"content":{"rendered":"<p>Last year when I was really starting to jump into exporting data to Excel I ran into an issue. I wanted the rows with duplicated data to only show the first row and hide the following rows&#8230; Conditional Formatting, right? So, why couldn&#8217;t I get what I wanted. When all else fails *Google* it! Which is just what I did and found exactly what I needed on <a href=\"http:\/\/blog.contextures.com\/archives\/2009\/09\/30\/hide-duplicate-headings-in-excel-report\/\" target=\"_blank\">Contextures Blog<\/a> then\u00a0just convert the Excel Macro into VBA and this&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">     Const xlUp As Long = -4162 'This can go at the very tip under the Declarations\r\n     Dim ApXL As Object\r\n     Dim xlWBk As Object\r\n     Dim xlWSh As Object\r\n     Dim lngLastRow As Long\r\n     Dim Z As String\r\n\r\nWith xlWSh\r\n     'Conditional Formatting\r\n     lngLastRow = xlWSh.Cells(.Rows.Count, 1).End(xlUp).Row\r\n     Z = &quot;A4&quot; &amp; &quot;:F&quot; &amp; lngLastRow\r\n                \r\n     xlWSh.Range(Z).Select\r\n     '.Add Type:xlExpression use 1 for Early Binding, 2 for Late Binding\r\n     ApXL.Selection.FormatConditions.Add Type:=2, Formula1:=&quot;=A3=A2&quot;\r\n     ApXL.Selection.FormatConditions(ApXL.Selection.FormatConditions.Count).SetFirstPriority\r\n          With ApXL.Selection.FormatConditions(1).Font\r\n               .Color = RGB(255, 255, 255)\r\n               .TintAndShade = 0\r\n          End With\r\n     ApXL.Selection.FormatConditions(1).StopIfTrue = False\r\nEnd With\r\n<\/pre>\n<p>&#8230;produces this&#8230;<\/p>\n<p><span style=\"color: #000000; font-family: Segoe UI; font-size: small;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-956\" src=\"http:\/\/regina-whipp.com\/blog\/wp-content\/uploads\/2016\/07\/HideDuplicates.png\" alt=\"\" width=\"650\" height=\"249\" \/><\/span><\/p>\n<p>Note, the code includes some caveats&#8230; I never knew how many rows hence *Z* and *lngLastRow* and since I have a Totals row I needed to know for highlighting and summing. If you don&#8217;t have that limitation you can use (change the column and row numbers accordingly)&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">xlWSh.Range(&quot;D4:D100&quot;).Select<\/pre>\n<p>&#8230;and eliminate *Z* and *lngLastRow*.<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_861\" class=\"pvc_stats all  \" data-element-id=\"861\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Last year when I was really starting to jump into exporting data to Excel I ran into an issue. I wanted the rows with duplicated data to only show the first row and hide the following rows&#8230; Conditional Formatting, right? So, why couldn&#8217;t I get what I wanted. When all else fails *Google* it! Which [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_861\" class=\"pvc_stats all  \" data-element-id=\"861\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,79],"tags":[34,21],"class_list":["post-861","post","type-post","status-publish","format-standard","hentry","category-access-tips","category-excel","tag-excel","tag-vba","odd"],"_links":{"self":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=861"}],"version-history":[{"count":7,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/861\/revisions"}],"predecessor-version":[{"id":1344,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/861\/revisions\/1344"}],"wp:attachment":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}