spacecaptainsuperguy
Board Regular
- Joined
- Dec 30, 2004
- Messages
- 202
- Office Version
- 365
- Platform
- Windows
I have a list of accounts structured as "Entity"-"Account#" with a dash in the middle such as ABC-123. The data on the left of the dash can be variable in length and contain both letters and numbers.
I'd like to extract a list of unique Entities (i.e. the left side of the dash). I was able to find the following code online which gets me close:
The catch is this code only works if the list had all the account numbers already removed. Rather than stripping off the account numbers and creating a whole new list to work from, I would like to try to build into this code to have it check the data left of the dash to see if it is unique or not. I'm guessing it would be this line of code that would need to be changed to do that?
UniqColl.Add cell.Value, cell.Value
But have no idea how to go about writing that out other than the formula to do so.
Any thoughts are much appreciated.
I'd like to extract a list of unique Entities (i.e. the left side of the dash). I was able to find the following code online which gets me close:
VBA Code:
Sub GetUnique_Collection() 'Using the Collection object
'
Dim SourceRng As Range
Dim UniqColl As New Collection
Set SourceRng = Range("A2:A30")
On Error Resume Next
For Each cell In SourceRng.Cells
UniqColl.Add cell.Value, cell.Value
Next
On Error GoTo 0
ReDim UniqArray(1 To UniqColl.Count)
For i = 1 To UniqColl.Count
UniqArray(i) = UniqColl(i)
Next
'Optional sort routine can be inserted here
Range("H1").Resize(UniqColl.Count, 1).Value = WorksheetFunction.Transpose(UniqArray)
End Sub
The catch is this code only works if the list had all the account numbers already removed. Rather than stripping off the account numbers and creating a whole new list to work from, I would like to try to build into this code to have it check the data left of the dash to see if it is unique or not. I'm guessing it would be this line of code that would need to be changed to do that?
UniqColl.Add cell.Value, cell.Value
But have no idea how to go about writing that out other than the formula to do so.
Any thoughts are much appreciated.