There could be a few reasons why entries are being duplicated in your VBA Dictionary when using CStr for keys:
1) Case sensitivity: CStr converts all keys to strings, which may cause issues if there are keys that differ only in case. For example, "Hello" and "hello" would be treated as different keys. To avoid this, you can use LCase or UCase to ensure that all keys are in the same case.
2) Trailing spaces: If your input strings contain trailing spaces, CStr may treat them as different keys. To avoid this, you can use the Trim function to remove any leading or trailing spaces before using CStr.
3) Null or empty values: If your input values are null or empty, CStr may convert them to the same string value, resulting in duplicate entries in the dictionary. To avoid this, you can add a check to ensure that the key is not null or empty before adding it to the dictionary.
Overall, it is important to ensure that your keys are unique and consistent when using a Dictionary object in VBA.
Asked: 2023-07-03 07:17:51 +0000
Seen: 13 times
Last updated: Jul 03 '23