FIND SPECIFIC VALUE...IF FOUND RETURN SPECIFIC VALUE

Nasturtium

New Member
Joined
Jun 6, 2016
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have a column with 3500 addresses. I need to search the column for things like Unit?? or RR?? or PO Box??. The addresses are not all entered the same. Some have the Unit at the front and some at the end. Same with PO Box. If it searches using a wildcard like Unit???/Unit* and finds the value Unit 7 then return that value. If it finds Unit 12 then return Unit 12. I can create more than one search so it's not all in one formula. I can do all the Units first then RR then PO Box, etc. I'll want the results of the search posted in the adjacent column.

ConnectON V11.xlsm
F
4525 Raglan Street
469608 Carter Road
47250 Elm St
485139 Trussler Road RR 3
49395 Waydom Drive
502132 Greenfield Road
512132 Greenfield Road
522132 Greenfield Road
531271 Reidsville Road
54141705 Grey Road 9
55141705 Grey Road 9
56Portage Landing 3119 Highway 169, Unit 2
571074 Cranberry Road , PO Box 24
581074 Cranberry Road , PO Box 24
5926 Saunders Road
6075 Welham Road
6175 Welham Road
6231 King Street, Unit 6
ConnectON


When I'm done I want all the addresses to just contain the street number and name. I want to remove all the references to units, RR, PO Box. I'll want to delete them after I've found them and placed them in the adjacent column. I want it to look something like the example below

ConnectON V11.xlsm
AB
125 Raglan Street
29608 Carter Road
3250 Elm St
45139 Trussler RoadRR 3
5395 Waydom Drive
62132 Greenfield Road
72132 Greenfield Road
82132 Greenfield Road
91271 Reidsville Road
10141705 Grey Road 9
11141705 Grey Road 9
12Portage Landing 3119 Highway 169Unit 2
131074 Cranberry RoadPO Box 24
141074 Cranberry RoadPO Box 24
1526 Saunders Road
1675 Welham Road
1775 Welham Road
1831 King StreetUnit 6
Sheet1


I hope all this makes sense. Please feel free to ask if you need additional information.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I can give you a True or False in the next column with Power Query. This can then be filtered for all "Trues."

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Column1], "Unit") or Text.Contains([Column1],"PO Box") or Text.Contains([Column1],"RR ") then "True" else "False")
in
    #"Added Custom"

Book10
AB
1Column1Custom
225 Raglan StreetFalse
39608 Carter RoadFalse
4250 Elm StFalse
55139 Trussler Road RR 3True
6395 Waydom DriveFalse
72132 Greenfield RoadFalse
82132 Greenfield RoadFalse
92132 Greenfield RoadFalse
101271 Reidsville Road False
11141705 Grey Road 9False
12141705 Grey Road 9False
13Portage Landing 3119 Highway 169, Unit 2True
141074 Cranberry Road , PO Box 24True
151074 Cranberry Road , PO Box 24True
1626 Saunders RoadFalse
1775 Welham RoadFalse
1875 Welham RoadFalse
1931 King Street, Unit 6True
Table1
 
Upvote 0
I was going to write VBA code to do this, but I used helper columns with Excel formulas instead.
Output.PNG


Here are the formulas:
Formulas.PNG


Instructions:
  • In the top/header row, type in all of the address parts "PO Box", "RR " (with the space!), "Unit",etc.
  • Put
    Excel Formula:
    =IF(H45<>"",IF(J45>0,MID(F45,1,J45-1),MID(F45,1,I45-1)),F45)
    in cell G45 and fill down.
  • Put
    Excel Formula:
    =IF(I45>0,MID(F45,I45,LEN(F45)),"")
    in Cell H45 and fill down.
  • Put
    Excel Formula:
    =SUM(K45:M45)
    in Cell I45 and fill down. (This assumes that you won't have both Unit # and PO Box # in the same cell, for example.)
  • Put
    Excel Formula:
    =IFERROR(SEARCH(",",F45,1),0)
    in Cell J45 and fill down.
  • Put
    Excel Formula:
    =IFERROR(SEARCH(K$44,$F45,1),0)
    in Cell K45. Fill right to the last address part column and then fill down
You can simply hide these helper columns after you're done.

If you want someone to write VBA code to do this, let us know (since you have a .xlsm file extension).
 
Upvote 0
Solution
I was going to write VBA code to do this, but I used helper columns with Excel formulas instead.
View attachment 47495

Here are the formulas:
View attachment 47497

Instructions:
  • In the top/header row, type in all of the address parts "PO Box", "RR " (with the space!), "Unit",etc.
  • Put
    Excel Formula:
    =IF(H45<>"",IF(J45>0,MID(F45,1,J45-1),MID(F45,1,I45-1)),F45)
    in cell G45 and fill down.
  • Put
    Excel Formula:
    =IF(I45>0,MID(F45,I45,LEN(F45)),"")
    in Cell H45 and fill down.
  • Put
    Excel Formula:
    =SUM(K45:M45)
    in Cell I45 and fill down. (This assumes that you won't have both Unit # and PO Box # in the same cell, for example.)
  • Put
    Excel Formula:
    =IFERROR(SEARCH(",",F45,1),0)
    in Cell J45 and fill down.
  • Put
    Excel Formula:
    =IFERROR(SEARCH(K$44,$F45,1),0)
    in Cell K45. Fill right to the last address part column and then fill down
You can simply hide these helper columns after you're done.

If you want someone to write VBA code to do this, let us know (since you have a .xlsm file extension).
That is amazing! This will do nicely! No need for VBA. There's always more than one way to solve it but if it works why do anything else!! Thanks again!
 
Upvote 0
That is amazing! This will do nicely! No need for VBA. There's always more than one way to solve it but if it works why do anything else!! Thanks again!
You're quite welcome! I'm glad that this worked for you!

(And obviously there is no limit to the number of address parts you can use. Just be sure to take note of the extra space in "RR ", because the formulas would mark cells that have rr (as in "Cranberry Road"). Yeah, it's not very smart!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top