Hello.
My question is about the Mid function.
I know the below code removes a specified portion of a string from a longer string.
Sub AssignRemovedContents()
Dim sContentsRemoved As String
Dim sTheString As String
Dim lLetterStart As Long
Dim lLetterEnd As Long
Dim lTotalPositions As Long
sTheString = "This is the string"
lTotalPositions = Len(sTheString)
lLetterStart = 9
lLetterEnd = 18
sContentsRemoved = Mid(sTheString, lLetterStart, lLetterEnd - lLetterStart + 1)
MsgBox "The contents removed from the " & lTotalPositions & " string positions are: " & sContentsRemoved
End Sub
The above assigns the variable sContentsRemoved with the value of the removed contents: "the string"
However, I want to do the opposite of the above.
I want to assign a variable with the contents remaining in the string, not the contents taken out of the string.
So, in the example above, I'd want to assign a variable sContentsRemaining with the value "This is "
In my actual program, I don't know the contents that will remain in the string, which is why I can't just pull them out specifically.
I only know the contents in the string I don't want. Thus, I hope to use my knowledge of the contents I do not want, in order to separate them from the contents that I DO want.
Any help would be greatly appreciated! Thanks so much!!
Bookmarks