Solved

Finding and replacing variable text using a formula

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

726 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