CluelessInVBA
New Member
- Joined
- Nov 8, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Greetings,
I have a set of IDs, stored in a 1D-Array A. The IDs are already sorted alphabetically and all of them are unique. Now, I want to find the index of said IDs in another array B, where the IDs are although sorted alphabetically, but many of them are duplicated (E.G. ID "DESHPDHK0003idyj" is 3 times in the Array B). Array A is just Array B, on which I used a function to remove duplicates (RemoveDupes). Usually, I would just use the Match function to find the indices of said IDs, but it doesn't work, since some IDs are basically named the same ("DESHPDHK0003idyj" and "DESHPDHK0003idYJ") but are written in different uppercase and lowercase letters. When using Match, it would just return ONE index for "DESHPDHK0003idyj" and "DESHPDHK0003idYJ" when in reality, it should return two indices.
The function to remove dupes also worked, since it didn't remove "false" duplicates (e.g. "DESHPDHK0003idyj" and "DESHPDHK0003idYJ"). I've also tried using the code of the RemoveDupes function to find a solution, but I couldn't. Here is the snippet of said function, if needed:
Thank you all in advance!
I have a set of IDs, stored in a 1D-Array A. The IDs are already sorted alphabetically and all of them are unique. Now, I want to find the index of said IDs in another array B, where the IDs are although sorted alphabetically, but many of them are duplicated (E.G. ID "DESHPDHK0003idyj" is 3 times in the Array B). Array A is just Array B, on which I used a function to remove duplicates (RemoveDupes). Usually, I would just use the Match function to find the indices of said IDs, but it doesn't work, since some IDs are basically named the same ("DESHPDHK0003idyj" and "DESHPDHK0003idYJ") but are written in different uppercase and lowercase letters. When using Match, it would just return ONE index for "DESHPDHK0003idyj" and "DESHPDHK0003idYJ" when in reality, it should return two indices.
The function to remove dupes also worked, since it didn't remove "false" duplicates (e.g. "DESHPDHK0003idyj" and "DESHPDHK0003idYJ"). I've also tried using the code of the RemoveDupes function to find a solution, but I couldn't. Here is the snippet of said function, if needed:
VBA Code:
Function RemoveDupes(InputArray) As Variant
Dim OutputArray As Variant
Dim CurrentValue As Variant
Dim A As Variant
On Error Resume Next
OutputArray = Array("")
For Each CurrentValue In InputArray
Flag = 0
If IsEmpty(CurrentValue) Then GoTo skip
For Each A In OutputArray
If A = CurrentValue Then
Flag = 1
Exit For
End If
Next A
If Flag = 0 Then
ReDim Preserve OutputArray(UBound(OutputArray, 1) + 1)
OutputArray(UBound(OutputArray, 1) - 1) = CurrentValue
End If
skip:
Next
RemoveDupes = OutputArray
Thank you all in advance!
Last edited by a moderator: