Solved

search and get a string from a line

Posted on 2013-06-19
3
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Office 365 Training for Admins

Learn how to provision tenants, synchronize on-premise Active Directory, and implement Single Sign-On with these master level course.  Only from Platform Scholar

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

738 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