Solved

Finding and replacing variable text using a formula

Posted on 2014-10-28
4
180 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
[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
  • 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 51

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 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.

688 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