alam747
asked on
search and get a string from a line
Hi Experts,
I want search and get a string from a sentence.
for example, the string contain the word "LN_" but LN_ is not in the begining of the string it can be like "abc LN_defghijkelmopqrstuv" or "abcdefg LN_jkdjslajlkdjljflkjl"
I want to get the portion of the string start with LN_ up to the end of the string.
from above two strings I want to get "LN_defghijkelmopqrstuv" and "LN_jkdjslajlkdjljflkjl"
Please advise VBA code to do that.
Thanks
I want search and get a string from a sentence.
for example, the string contain the word "LN_" but LN_ is not in the begining of the string it can be like "abc LN_defghijkelmopqrstuv" or "abcdefg LN_jkdjslajlkdjljflkjl"
I want to get the portion of the string start with LN_ up to the end of the string.
from above two strings I want to get "LN_defghijkelmopqrstuv" and "LN_jkdjslajlkdjljflkjl"
Please advise VBA code to do that.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot
Text = ""
i = InStr(1, Source, "LN")
If i > 0 Then Text = Mid(Source, i)
The first statement (clearing the value of Text variable) is required if you are returning values from more than one cell. Without it, if the second (or later) cell doesn't contain LN, then Text would repeat its preceding value.