title: How to delete duplicate elements from VBscript/VBA array to use in drop down box in Excel
body: <p>I'm finding a lot of articles close to mine, but not quite what I'm looking for. I'm working with the IBM Personal Communications emulator to gather patient history data. There can be several pages of claims on the patient history, so the service codes used later in the program need to be gathered and saved in an array. Once duplicates are removed, the remaining codes will be stored in a drop down box.</p>
  
  <pre><code>' Copies entire current history screen
  MHIScreen = objUNET.autECLPS.GetText(3, 1, 1680)
  
  ' Location of the place of service code header
  POSLoc = InStr(MHIScreen, "PS  SVC")
  
  ' Location of service code
  ServLoc = POSLoc + 3
  
  ' Used for array index
  j = 1
  Row = 4
  
  Do
      Serv(j) = Mid(MHIScreen, ServLoc, 6)
      Range("D" &amp; Row).Value = Serv(j)
      ServLoc = ServLoc + 320
      j = j + 1
      Row = Row + 1
  Loop Until SMonth &gt; EMonth
  </code></pre>
  
  <p>The output of this could look like this:</p>
  
  <pre><code>12345
  12345
  23456
  12345
  34567
  34567
  12345
  98765
  </code></pre>
  
  <p>The desired result would be to filter through the duplicates and end up with this:</p>
  
  <pre><code>12345
  23456
  34567
  98765
  </code></pre>
  
  <p>These would the be put into a drop down box for the user to choose from. I wanted to see where in the element one particular code would be located, but when I add the following line of code, I get 0 because j is already higher than the index of the last code and <code>Serv(j)</code> is empty:</p>
  
  <pre><code>Result = InStr(Serv(j), "34567")
  </code></pre>
  
  <p>Is there anyone who can guide me to a solution?</p>