How to build formula to check address structure?

darrenmccoy

New Member
Joined
Mar 26, 2019
Messages
37
Office Version
  1. 2019
Hi, Could you guys help me with what type of formula would I use to check address formatting and return a true or false?

An example case would be the format of address must be (number, street names, location, state zip) with the commas and spaces.

IDFULL ADDRESSVALIDATION
611762101 SMITHS LANE, PEARCEDALE, VIC 3912TRUE
6330901,2,3 RIVER STREET, SOUTH YARRA, VIC 3141FALSE
6330981A MATTHEWS COURT, TOORAK, VIC 3142TRUE
63310043/10 CAPISTRANO PLACE, MELBOURNEFALSE
6331021/17 WELL STREET, BRIGHTON, VIC 3186TRUE
6331031&2 DOW STREET, MELBOURNE, VIC 3207FALSE
63312674 WITHERS STREET, ALBERT PARK, VIC 3206TRUE
633129CAMP STREET, CHELSEA, VIC 3196FALSE
63313033 BODLEY STREET BEAUMARIS VIC 3193FALSE
63313114 NORTH ROAD, BRIGHTON, VIC 3186TRUE

I realise there are a heap of variables that may exist, is there a base checking formula I can use to determine if the correct format exists?

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I would use vba to try to do this. Is that acceptable?

Can you clarify the 'rules' for 'number'.
For example, I presume 633103 fails due to 1&2 for 'number'?
Would 1-2 DOW STREET be acceptable?
What about these
3-5/10 DOW STREET?
UNIT 7 DOW STREET?

Are all texts in upper case like you samples?
 
Upvote 0
I would use vba to try to do this. Is that acceptable?

-- Thanks, I do not know how to write VBA, but I can add it if I have the script. Generally if I can run a formula I will because often I use gSuite as well for different dataset ---

Can you clarify the 'rules' for 'number'.
For example, I presume 633103 fails due to 1&2 for 'number'? -- YES ---
Would 1-2 DOW STREET be acceptable? -- YES ---
What about these
3-5/10 DOW STREET? -- YES ---
UNIT 7 DOW STREET? -- NO, that would fail ---

Are all texts in upper case like you samples? - -- YES ---
 
Upvote 0
I would be happy for somebody to prove me wrong but I don't think this is feasible with standard worksheet functions. However, this user-defined function is pretty short & the instructions to set it up are ...

1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you may use the icon at the top right of the code pane) into the main right hand pane that opens at step 2
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

If the function does not work for some cases, please provide details & examples.

VBA Code:
Function IsValid(s As String) As Boolean
  Dim RX As Object
  
  Set RX = CreateObject("VBScript.RegExp")
  RX.Pattern = "(^\d[^& \,]* )([A-Z\- ']+\, ){2}(QLD|NSW|VIC|TAS|SA|WA|NT|ACT)( \d{4}$)"
  IsValid = RX.Test(s)
End Function

darrenmccoy 2020-03-14 1.xlsm
ABC
1IDFULL ADDRESSVALIDATION
2611762101 SMITHS LANE, PEARCEDALE, VIC 3912TRUE
36330901,2,3 RIVER STREET, SOUTH YARRA, VIC 3141FALSE
46330981A MATTHEWS COURT, TOORAK, VIC 3142TRUE
563310043/10 CAPISTRANO PLACE, MELBOURNEFALSE
66331021/17 WELL STREET, BRIGHTON, VIC 3186TRUE
76331031&2 DOW STREET, MELBOURNE, VIC 3207FALSE
863312674 WITHERS STREET, ALBERT PARK, VIC 3206TRUE
9633129CAMP STREET, CHELSEA, VIC 3196FALSE
1063313033 BODLEY STREET BEAUMARIS VIC 3193FALSE
1163313114 NORTH ROAD, BRIGHTON, VIC 3186TRUE
126331031-2 DOW STREET, MELBOURNE, VIC 3207TRUE
136331033-5/10 DOW STREET, MELBOURNE, VIC 3207TRUE
14633103UNIT 7 DOW STREET, MELBOURNE, VIC 3207FALSE
Sheet1
Cell Formulas
RangeFormula
C2:C14C2=IsValid(B2)
 
Upvote 0
Wow, That's so simple and amazing!
Thank you so much!
Screenshot of it in action and working:
1584178302650.png
 
Upvote 0
Peter, How do I save that function so as to be able to use it in any spreadsheet?
 
Upvote 0
Wow, That's so simple and amazing!
Thank you so much!
Screenshot of it in action and working:
You're welcome. Glad it worked for you. :)

How do I save that function so as to be able to use it in any spreadsheet?
If you open the vba window again (Alt+F11 is one way) do you see PERSONAL.XLSB in the Project Explorer pane at the left?

1584179784299.png


If so, select it then Insert -> Module as we did before and past the function code in that new module & Save
If not, post back & I'll give further instruction.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,515
Messages
6,125,277
Members
449,220
Latest member
Excel Master

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