Solved

Finding and replacing variable text using a formula

Posted on 2014-10-28
4
177 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 50

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

839 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