Este exemplo mostra como usar o método AddTop10 para exibir os primeiro 10% de uma série de números numa planilha do MS Excel.
Sub DemoAddTop10()' Fill a range with random numbers.' Mark the top 10% of items in green, and the bottom' 10% of the items in red.' Set up a range, and fill it with random numbers.Dim rng As RangeSet rng = Range("A1:E10")SetupRangeData rng' Clear any existing format conditions.rng.FormatConditions.Delete' Set up a condition that formats the top' 10 percent of items on green.Dim fc As Top10Set fc = rng.FormatConditions.AddTop10fc.Percent = Truefc.TopBottom = xlTop10Topfc.Interior.Color = vbGreen' Set up a condition that formats the bottom' 10 percent of items in red.Set fc = rng.FormatConditions.AddTop10fc.TopBottom = xlTop10Bottomfc.Percent = Truefc.Interior.Color = vbRedEnd SubSub SetupRangeData(rng As Range)rng.Formula = "=RANDBETWEEN(1, 100)"End Sub
Tags: VBA, Excel, Display, Top Ten, Percent, Ranges, Programmatically