{"id":6401,"date":"2021-11-19T05:39:55","date_gmt":"2021-11-19T05:39:55","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=6401"},"modified":"2021-11-19T05:40:45","modified_gmt":"2021-11-19T05:40:45","slug":"macro-to-remove-some-text-with-condition-and-add-color-shade","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/macro-to-remove-some-text-with-condition-and-add-color-shade\/21190.html","title":{"rendered":"Macro To Remove Some Text With Condition And Add Color Shade"},"content":{"rendered":"<p>&lt;td&gt;Hello,&lt;p&gt;So I made a macro to format a table. I will post the macro below and there are comments that explain things.&lt;\/p&gt;&lt;p&gt;Here&#8217;s how my table looks like: &lt;a href=&#8221;https:\/\/web.archive.org\/web\/20201204141704\/http:\/\/i65.tinypic.com\/1606l5f.jpg&#8221; target=&#8221;_blank&#8221; rel=&#8221;nofollow&#8221;&gt;http:\/\/i65.tinypic.com\/1606l5f.jpg&lt;\/a&gt;&lt;br&gt;No, there is no shading on the cells, it&#8217;s the background I use (as a Windows OS setting).&lt;br&gt;I hope the picture can be displayed.&lt;\/p&gt;&lt;p&gt;&lt;b&gt;I would like to do 2 more things, and I don&#8217;t know how:&lt;\/b&gt;&lt;br&gt;&lt;b&gt;1.&lt;\/b&gt; Remove the white text &#8211; either remove it after the conditional formatting VBA, or replace the conditional formatting VBA with some code to remove all duplicates except first occurrence from columns A and B only.&lt;\/p&gt;&lt;p&gt;I tried several codes found online and adapted, but none worked. I&#8217;m guessing because of the conditional formatting, but dunno really.&lt;\/p&gt;&lt;p&gt;&lt;b&gt;2.&lt;\/b&gt; Add cell color red or whatever to the entire rows that contain a client in column B, but only to those rows (they would be 2, 18 and 24 in the image). &lt;\/p&gt;&lt;p&gt;&lt;b&gt;Here is my macro without parts that I think are irrelevant to fonts and shading:&lt;\/b&gt;&lt;\/p&gt;&lt;p&gt;&lt;\/p&gt;&lt;pre&gt;&#8217; Page setup: A4, Portrait, Center horizontally, Zoom 100%.<br \/>\nWith ActiveSheet.PageSetup<br \/>\n.LeftMargin = Application.CentimetersToPoints(0.196850393700787)<br \/>\n.RightMargin = Application.CentimetersToPoints(0.196850393700787)<br \/>\n.TopMargin = Application.CentimetersToPoints(0.393700787401575)<br \/>\n.BottomMargin = Application.CentimetersToPoints(0.393700787401575)<br \/>\n.HeaderMargin = Application.CentimetersToPoints(0.393700787401575)<br \/>\n.FooterMargin = Application.CentimetersToPoints(0.393700787401575)<br \/>\n.PrintHeadings = False<br \/>\n.PrintGridlines = False<br \/>\n.PrintComments = xlPrintNoComments<br \/>\n.PrintQuality = 300<br \/>\n.CenterHorizontally = True<br \/>\n.CenterVertically = False<br \/>\n.Draft = False<br \/>\n.PaperSize = xlPaperA4<br \/>\n.FirstPageNumber = xlAutomatic<br \/>\n.Order = xlDownThenOver<br \/>\n.BlackAndWhite = False<br \/>\n.Zoom = 100<br \/>\n.PrintErrors = xlPrintErrorsDisplayed<br \/>\n.OddAndEvenPagesHeaderFooter = False<br \/>\n.DifferentFirstPageHeaderFooter = False<br \/>\n.ScaleWithDocHeaderFooter = False<br \/>\n.AlignMarginsHeaderFooter = False<br \/>\nEnd With<\/p>\n<p>&#8216; Conditional formatting: color in white any duplicate values, except their first appearance.<br \/>\nRange(&#8220;A2:A279&#8243;).Select<br \/>\nSelection.FormatConditions.Add Type:=xlExpression, Formula1:=&#8221;=A1=A2&#8221;<br \/>\nSelection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority<br \/>\nWith Selection.FormatConditions(1).Font<br \/>\n.ColorIndex = 2 &#8216; white color<br \/>\n.TintAndShade = 0<br \/>\nEnd With<br \/>\nSelection.FormatConditions(1).StopIfTrue = False<\/p>\n<p>&#8216; Conditional formatting: color in white any duplicate values, except their first appearance.<br \/>\nRange(&#8220;B2:B279&#8243;).Select<br \/>\nSelection.FormatConditions.Add Type:=xlExpression, Formula1:=&#8221;=B1=B2&#8221;<br \/>\nSelection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority<br \/>\nWith Selection.FormatConditions(1).Font<br \/>\n.ColorIndex = 2 &#8216; white color<br \/>\n.TintAndShade = 0<br \/>\nEnd With<br \/>\nSelection.FormatConditions(1).StopIfTrue = False<\/p>\n<p>&#8216; Conditional formatting font face and font size for LANDSCAPE page<br \/>\n&#8216; arial font by default; if you want other, add line Cell.Font.Name = &#8220;Font Name&#8221;<br \/>\nFor Each Cell In ActiveSheet.UsedRange<br \/>\nIf ActiveSheet.PageSetup.Orientation = xlPortrait Then<br \/>\nCell.Font.Size = 12 &#8216; font size for PORTRAIT<br \/>\nCell.Font.Name = &#8220;Tahoma&#8221;<br \/>\nElse<br \/>\nCell.Font.Size = 16 &#8216; font size for LANDSCAPE<br \/>\nCell.Font.Name = &#8220;Tahoma&#8221;<br \/>\nEnd If<br \/>\nNext Cell<\/p>\n<p>&#8216; Delete text of white color in columns A and B &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; NOT WORKING<br \/>\nDim rng As Range<br \/>\nSet rng = [B2:B279]<br \/>\nFor Each Cell In rng<br \/>\nIf Cell.Font.ColorIndex = 2 Then<br \/>\nCell.ClearContents<br \/>\nEnd If<br \/>\nNext Cell<\/p>\n<p>&#8216; Add shading to row if cell with black text is in column B &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; TBA<br \/>\n&#8216; TO BE ADDED&lt;\/pre&gt;&lt;br&gt;&lt;p align=&#8221;right&#8221;&gt;&lt;font size=&#8221;1&#8243;&gt;&lt;i&gt;message edited by Mrrrr&lt;\/i&gt;&lt;\/font&gt;&lt;\/p&gt;&lt;\/td&gt;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":13},"question-category":[53],"question_tags":[],"class_list":["post-6401","question","type-question","status-publish","hentry","question-category-office"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/6401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=6401"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=6401"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=6401"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=6401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}