I'm writing a function that will get a string and split it into words and apply formatting to each word accordingly (based on my rules).
For example: JOHN ALPHA BRAVO will be John Alpha Bravo and AD67 TRIALS willl become AD67 Trials. Something like that.
Anyway, I'm only in the beginning of my code and can't quite comprehend why it won't work.
I wrote the following code to split the text and put them into an array. I can fill the 1st slot in the array but the For loop won't continue.
It does not return any error whatsoever so I really don't know what to do.
Public Function test(source As String) As Variant 'test(John Alpha Bravo)
Dim words() As String
Dim word_count As Integer
Dim spaces() As Integer
word_count = Len(source) - Len(Replace(source, " ", "")) 'word_count = 2
ReDim words(word_count) 'words(2)
ReDim spaces(word_count) 'words(2)
For counter = 0 To word_count 'counter = 0 To 2
spaces(counter) = (InStr(1, source, " ")) 'spaces(0) = 5
words(counter) = Mid(source, 1, spaces(counter) - 1) 'words(0) = "John"
source = Mid(source, ((spaces(counter)))) 'source = " Alpha Bravo"
Next counter
test = source
End Function
At the moment, words(0) is equal to John, words(1) is blank and so is words(2).
Thank you in advance for anyone that'll take their time and help me!
Bookmarks