Solved

Finding and replacing variable text using a formula

Posted on 2014-10-28
4
169 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
Comment Utility
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 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

In which case would this formula be not valid

=LEFT(B9,5)

Regards
0
 

Author Comment

by:David Phelops
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Slight Modification to Macro 2 14
TT Column Arrange 10 26
Visual Studio 2005 text editor 10 18
How to compare data in excel 5 26
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now