Excel.AddUnique Method in MS Excel to Display Unique Numbers in Ranges in VB.NET

In this article I am going to explain about how to Display Unique Numbers in Ranges in Microsoft Excel 2010.
  • 1414

Introduction

In this article I am going to explain about how to Display Unique Numbers in Ranges in Microsoft Excel 2010. For this we use Excel.AddUnique Method. Using this method we can find unique numbers in ranges.
 
Microsoft Office 2010 offer some powerful tools, using this tools you can create application. Using Microsoft Visual Basic for Applications (VBA) you can create your own application according to your need. These application can performer some specific task.

For creating application we can use

  • VBA host of Excel 2010
  • VBA host of PowerPoint 2010
  • VBA host of Word 2010

NOTE : OneNote 2010 is not a VBA host.

Code that we use in this application are given below

Sub DemoAddUnique()
    
' Set up a range, and fill it with random numbers.
    Dim vip As Range
    vip = Range("A1:E10")
    SetupRangeData(vip)
    
' Clear any existing format conditions.
    vip.FormatConditions.Delete()
    
' Display all unique values in red.
    Dim vipuv As UniqueValues
    vipuv = vip.FormatConditions.AddUniqueValues
    vipuv.DupeUnique = xlUnique
    vipuv.Interior.Color = vbRed
    
' Display all duplicate values in yellow and in bold.
    uv = vip.FormatConditions.AddUniqueValues
    vipuv.DupeUnique = xlDuplicate
    vipuv.Interior.Color = vbYellow
    vipuv.Font.Bold = 
True
End Sub

 Sub SetupRangeData(vip As Range)
   vip.Formula = 
"=RANDBETWEEN(1, 100)"

End Sub

Step for creating Application

Step 1 : Start MS Excel 2010 :

1.jpg

2.jpg
 

Step 2 : Using Alt + F11 Key Start Visual Basic for Applications (VBA) Window :

3.jpg
 

Step 3 : Select on Sheet 1 :

4.jpg
 

Step 4 : Right Click on Sheet 1 and select View Code :

5.jpg

6.jpg
 

Step 5 : Write Code in Visual Basic for Applications (VBA) Window :

7.jpg
 

Step 6 : Run Application using F5 :

Step 7 : Macros window will open, Select Macros name and click on Run Button :

8.jpg
 

Step 8 : Output of Application :

Every time it show different values when we run this application.
 

9.jpg

10.jpg

Clipboard20.jpg

Clipboard22.jpg

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.