[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

search and get a string from a line

Posted on 2013-06-19
3
Medium Priority
?
320 Views
Last Modified: 2013-06-23
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
0
Comment
Question by:alam747
3 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 39261500
Text = Mid(Source, Instr(Source, "LN_"))

Where Source = "abc LN_defghijkelmopqrstuv"

Kevin
0
 
LVL 81

Expert Comment

by:byundt
ID: 39262160
It is worth noting that you'll get a runtime error if LN is not in the string when combining MID with InStr. To avoid this, use three statements:
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.
0
 

Author Closing Comment

by:alam747
ID: 39269630
Thanks a lot
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question