Solved

Append to B2 with exclusions

Posted on 2016-07-26
13
55 Views
1 Endorsement
Last Modified: 2016-07-29
Append to contents of B2 with a dash (-), plus the contents from D2, and add the word "Branch" to the end.

Exclude integer at the beginning of an address.
Exclude every single character reference.
Example: If the company name in B2 is "ADVANCE STORES COMPANY, INCORPORATED" and the address in D2 is "610 N Loop 340", then the result would be "ADVANCE STORES COMPANY, INCORPORATED - Loop 340 Branch"
sample-for-ee.csv
1
Comment
Question by:frugalmule
[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
  • 7
  • 6
13 Comments
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41729843
Please try this....

1) Open your workbook

2) Press Alt+F11 to open VB Editor

3) On VB Editor --> Insert --> Module and paste the Function code given below into the opened code window.

4) Close VB Editor and save your workbook as Macro-Enabled Workbook

Now you can use the function CompanyWithAddress on the sheet as below...
In E2
=CompanyWithAddress(B2,D2)
and then copy it down.

Function Code:
Function CompanyWithAddress(cRng As Range, aRng As Range) As String
Dim RE As Object
Dim addStr As String
Set RE = CreateObject("VBScript.RegExp")
RE.Pattern = "\d+\s(\w\s)?"
If RE.Test(aRng.Value) Then
addStr = RE.Replace(aRng.Value, "")
End If
CompanyWithAddress = cRng & " - " & addStr & " Branch"
End Function

Open in new window


For details, refer to the attached where I have inserted the formula in col. E, highlighted yellow.
sample-for-ee.xlsm
0
 

Author Comment

by:frugalmule
ID: 41729887
Can I do it as a function, without the vba?
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41729904
Okay try this....

In E2

=B2&" - "&IF(FIND(" ",REPLACE(D2,1,FIND(" ",D2),""))=2,REPLACE(REPLACE(D2,1,FIND(" ",D2),""),1,2,""),REPLACE(D2,1,FIND(" ",D2),""))&" Branch"

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:frugalmule
ID: 41729958
Fantastic!  

Should also exclude any reference to a suite number (i.e. Ste 206).
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41729967
Please try this.....
=B2&" - "&IF(FIND(" ",REPLACE(D2,1,FIND(" ",D2),""))=2,IFERROR(REPLACE(REPLACE(REPLACE(D2,1,FIND(" ",D2),""),1,2,""),FIND("Ste ",REPLACE(REPLACE(D2,1,FIND(" ",D2),""),1,2,"")),255,""),REPLACE(REPLACE(D2,1,FIND(" ",D2),""),1,2,"")),IFERROR(REPLACE(REPLACE(D2,1,FIND(" ",D2),""),FIND("Ste ",REPLACE(D2,1,FIND(" ",D2),"")),255,""),REPLACE(D2,1,FIND(" ",D2),"")))&" Branch"

Open in new window

0
 

Author Comment

by:frugalmule
ID: 41730006
=B2&" - "&IF(FIND(" ",REPLACE(E2,1,FIND(" ",E2),""))=2,IFERROR(REPLACE(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,""),FIND("Ste ",REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),255,""),REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),IFERROR(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),FIND("Ste ",REPLACE(E2,1,FIND(" ",E2),"")),255,""),REPLACE(E2,1,FIND(" ",E2),"")))&" Branch"

Open in new window


I tried this syntax with E2 instead of D2 because I inserted column C for this output.  It isn't working.
0
 

Author Comment

by:frugalmule
ID: 41730010
It's working now.  I must have done something weird, sorry for the confusion
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41730012
Glad to know that. :)
0
 

Author Comment

by:frugalmule
ID: 41730023
Ok, I do have small handful of #VALUE! errors.

One of them appears when the cell in the E column is blank, but another one appears when the value in the E cell is 708 Saratoga which makes little sense to me.

I'm using the following syntax:
=B2&" - "&IF(FIND(" ",REPLACE(E2,1,FIND(" ",E2),""))=2,IFERROR(REPLACE(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,""),FIND("Ste ",REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),255,""),REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),IFERROR(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),FIND("Ste ",REPLACE(E2,1,FIND(" ",E2),"")),255,""),REPLACE(E2,1,FIND(" ",E2),"")))&" Branch"

Open in new window

0
 

Author Comment

by:frugalmule
ID: 41730071
Here is a subset of the sheet sorted by the 14 cells out of 1,088 total cells that are causing the #VALUE! error.
EE-value-error.xlsx
0
 
LVL 31

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41730609
Okay try this...

In C2
=IF(E2="",B2,B2&" - "&IF(IFERROR(FIND(" ",REPLACE(E2,1,FIND(" ",E2),"")),0)=2,IFERROR(REPLACE(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,""),FIND("Ste ",REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),255,""),REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),IFERROR(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),FIND("Ste ",REPLACE(E2,1,FIND(" ",E2),"")),255,""),REPLACE(E2,1,FIND(" ",E2),"")))&" Branch")

Open in new window

0
 

Author Comment

by:frugalmule
ID: 41733252
Ok, this is good but I do not need the string " Branch" anymore, and I don't think that I need the " - " either.
0
 
LVL 31

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41734904
Well in that case, try this.....

In C2
=IF(E2="",B2,B2&"  "&IF(IFERROR(FIND(" ",REPLACE(E2,1,FIND(" ",E2),"")),0)=2,IFERROR(REPLACE(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,""),FIND("Ste ",REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),255,""),REPLACE(REPLACE(E2,1,FIND(" ",E2),""),1,2,"")),IFERROR(REPLACE(REPLACE(E2,1,FIND(" ",E2),""),FIND("Ste ",REPLACE(E2,1,FIND(" ",E2),"")),255,""),REPLACE(E2,1,FIND(" ",E2),""))))

Open in new window

0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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.
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 will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

626 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