This should work according to another stack overflow post but its not:
Dim arrWsNames As String() = {"Value1", "Value2"}
Can anyone let me know what is wrong?
This should work according to another stack overflow post but its not:
Dim arrWsNames As String() = {"Value1", "Value2"}
Can anyone let me know what is wrong?
The problem here is that the length of your array is undefined, and this confuses VBA if the array is explicitly defined as a string. Variants, however, seem to be able to resize as needed (because they hog a bunch of memory, and people generally avoid them for a bunch of reasons).
The following code works just fine, but it's a bit manual compared to some of the other languages out there:
Try this:
example:
result:
enjoy
edit: i removed the duplicatedtexts deleting feature and made the code smaller and easier to use.
Then you can do something static like this:
Or something iterative like this:
In the specific case of a String array you could initialize the array using the Split Function as it returns a String array rather than a Variant array:
This allows you to avoid using the Variant data type and preserve the desired type for arrWsNames.
Using
works but
doesn't so I sitck to Variant