Solved

Finding and replacing variable text using a formula

Posted on 2014-10-28
4
176 Views
Last Modified: 2014-10-28
I have created a function to search for specific characters. in a text string:
Public Function SearchCell(TargetCell As Range, SearchString As String)

SearchCell = InStr(1, LCase(TargetCell), LCase(SearchString))

End Function

Open in new window


I have used this function in a nested "IF" formula.  However, the formula has ended up quite cumbersome.  There are 5 nested "IFs" for 5 possible scenarios.

The attached workbook contains a table of the different expected scenarios, with the desired outcome and the formula used to achieve this.

My questions:

1.  Is there a less cumbersome way of doing this? I have used a formula, rather than a VBA loop, because I have found it to be faster, in previous experience.
2. Does excel have an inbuilt way of finding different text
3. I tried using the Excel "Find & Replace" functions, but could not manipulate them to deal with so many different scenarios.

i hope that my explanation is clear.
Thanks very much.
David
Public-Function-SearchCell.xlsm
0
Comment
Question by:David Phelops
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40408297
Would this be any better for you?

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B4,"AM + escort",""),"PM + escort",""),"AM",""),"PM","")," + escort","")

Open in new window

0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40408301
Hi,

In which case would this formula be not valid

=LEFT(B9,5)

Regards
0
 

Author Comment

by:David Phelops
ID: 40408318
Thanks Rgonzo - in the example I submitted, it would be valid in all cases.  However, your question has highlighted the weakness in my submission....

The id code RW019 is only one of hundreds of diffreent identifiers, of different lengths and structure.
0
 

Author Closing Comment

by:David Phelops
ID: 40408336
Thanks - I did not know how to nest "Substitute"... Still, it gave me the opportunity to create a new (if redundant) function!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

772 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