Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Public Sub createListOfOwnersAndValues()
- Dim people As Collection
- Dim c As Range
- Set people = New Collection
- Dim person As Variant
- Dim personRangeStart As String
- Dim personRangeEnd As String
- Dim outputAreaStart As String
- outputAreaStart = "J2" 'what is the top left cell of where you want the output to appear?
- personRangeStart = "F2" 'what is the start cell of the list of names?
- personRangeEnd = "F135" 'what is the end cell of the list of names?
- Dim foundPerson As Boolean
- For Each c In Range(personRangeStart, personRangeEnd)
- 'scan through our people and see if our person is already there
- 'assume we havent found first of all
- foundPerson = False
- For Each person In people
- If person = c.Text Then
- foundPerson = True 'found him already existing
- End If
- Next
- If foundPerson = False Then
- people.Add (c.Text)
- End If
- 'people now contains our DISTINCT people
- Next
- 'now that we have our collection of distinct people, lets search for and output
- 'all the cslev5's that they use
- Dim stroutput As String
- Dim cslev As String
- Range(outputAreaStart).Select 'select output cell
- For Each person In people
- stroutput = ""
- 'for each person, scan F2-F135
- For Each c In Range(personRangeStart, personRangeEnd)
- If c.Text = person Then
- 'add the cslev5 to the string to output for that person
- cslev = c.Offset(0, -1).Text
- stroutput = stroutput & cslev & ";"
- End If
- Next
- 'put the name in the outputcell and the stroutput
- 'in the cell to the right of the outputcell
- ActiveCell.Value = person
- ActiveCell.Offset(0, 1).Value = stroutput
- 'set outputcell to outputcell below
- ActiveCell.Offset(1, 0).Select
- Next
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement