I am not disputing any of that. I just don't know that the OP is going to be able to adapt what you posted to their situation if they do not already have a good working knowledge of building arrays and/or dictionaries. If they did, they probably would not be asking the question.I know, that is just an example;
- Dictionary lookups have an average time complexity of O(1). This means that checking for the existence of an element is done in constant time, regardless of the size of the dictionary.
- Searching for a substring within a string using InStr has a time complexity of O(n×m), where n is the length of the string and m is the length of the substring. This approach becomes increasingly slower as the dataset grows.
I tried this sample code. However, depending on the cell matching which value in fruits - the value of: InStr(fruits, Worksheets("Paste").Range("E" & i)) varies from 1, 6, 20, 15.Well, not really. I wanted to know exactly what "do something" is - updating cells? posting a message? etc?
However, if the values in the cells match exactly one of those options (i.e. "strawberry"), then you do not need to split the string of values at all.
Just use the InStr function to see if it exists in the string, i.e.
The nice thing about this option is there is only one loop!VBA Code:fruits = "apple, banana, watermelon, tangerine" For i = 2 To finalRow_Paste_tab If InStr(fruits, Worksheets("Paste").Range("E" & i)) Then 'do something End If Next i
I am not really sure what you are saying. I think it is time to move off of generalities and move into specifics.I tried this sample code. However, depending on the cell matching which value in fruits - the value of: InStr(fruits, Worksheets("Paste").Range("E" & i)) varies from 1, 6, 20, 15.
And on occasion the cell value that is not even in fruits, the value of InStr(fruits, Worksheets("Paste").Range("E" & i)) is 22.
Trying to make sense of this and make it work.