Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Public Sub createListOfOwnersAndValues()
  4.  
  5.     Dim people As Collection
  6.     Dim c As Range
  7.     Set people = New Collection
  8.     Dim person As Variant
  9.     Dim personRangeStart As String
  10.     Dim personRangeEnd As String
  11.     Dim outputAreaStart As String
  12.     outputAreaStart = "J2"  'what is the top left cell of where you want the output to appear?
  13.    personRangeStart = "F2" 'what is the start cell of the list of names?
  14.    personRangeEnd = "F135" 'what is the end cell of the list of names?
  15.  
  16.     Dim foundPerson As Boolean
  17.    
  18.     For Each c In Range(personRangeStart, personRangeEnd)
  19.         'scan through our people and see if our person is already there
  20.        'assume we havent found first of all
  21.        foundPerson = False
  22.        
  23.         For Each person In people
  24.             If person = c.Text Then
  25.                 foundPerson = True 'found him already existing
  26.            End If
  27.         Next
  28.        
  29.         If foundPerson = False Then
  30.             people.Add (c.Text)
  31.         End If
  32.         'people now contains our DISTINCT people
  33.    Next
  34.    
  35.     'now that we have our collection of distinct people, lets search for and output
  36.    'all the cslev5's that they use
  37.    Dim stroutput As String
  38.     Dim cslev As String
  39.    
  40.     Range(outputAreaStart).Select   'select output cell
  41.    
  42.     For Each person In people
  43.         stroutput = ""
  44.         'for each person, scan F2-F135
  45.        For Each c In Range(personRangeStart, personRangeEnd)
  46.             If c.Text = person Then
  47.                 'add the cslev5 to the string to output for that person
  48.                cslev = c.Offset(0, -1).Text
  49.                 stroutput = stroutput & cslev & ";"
  50.             End If
  51.         Next
  52.         'put the name in the outputcell and the stroutput
  53.        'in the cell to the right of the outputcell
  54.        ActiveCell.Value = person
  55.         ActiveCell.Offset(0, 1).Value = stroutput
  56.         'set outputcell to outputcell below
  57.        ActiveCell.Offset(1, 0).Select
  58.     Next
  59.    
  60. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement