How to get unique values โ€‹โ€‹from a list of values โ€‹โ€‹using VBscript?

Suppose an Excel worksheet has a column named Student Names and the column has duplicate values. Let's say

Student ======= Arup John Mike John Lisa Arup 

Using VBScript, how can I get unique values โ€‹โ€‹as shown below?

 Arup John Lisa Mike 
+4
source share
1 answer

The VBScript tool to get unique elements is a dictionary: add all the elements as keys to the dictionary and dictionary. Keys () will return an array of unique keys - for each definition. In code:

  Dim aStudents : aStudents = Array("Arup", "John", "Mike", "John", "Lisa", "Arup") WScript.Echo Join(aStudents) Dim aUniqStudents : aUniqStudents = uniqFE(aStudents) WScript.Echo Join(aUniqStudents) ' returns an array of the unique items in for-each-able collection fex Function uniqFE(fex) Dim dicTemp : Set dicTemp = CreateObject("Scripting.Dictionary") Dim xItem For Each xItem In fex dicTemp(xItem) = 0 Next uniqFE = dicTemp.Keys() End Function 

output:

 Arup John Mike John Lisa Arup Arup John Mike Lisa 
+8
source

All Articles