Solved

search and get a string from a line

Posted on 2013-06-19
3
303 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 500 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

856 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