Can a macro help "tidy up" address data?

Leila-Marie

Board Regular
Joined
Aug 23, 2013
Messages
50
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:HyphenationZone>21</w:HyphenationZone> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--> Hi,


Today I’m trying to work out, if I can write or record a macro to help me tidy up some data.


The data is the addresses of a long, long list of companies.

In its current format, the data has 2 columns in each row. The first column contains the “Street” and “House number” and the second column contains the “Postal Code” and the “City”.

What I need to do is to separate these, so that I have 4 columns – a separate one for each piece of information.

(The reason for this is that they will be imported into a CRM database and that program needs these pieces of information separately.)

So, I’ve already developed a macro for tidying up the “Postal Code and City” cells. That was pretty easy.

However, the “Street and House number” cells are much trickier.

Sometimes the Street name is just one word, sometimes two words, sometimes three words.

And the “House number” is not always just a number. Sometimes there are numbers like “17 c” or “16-18” or “42 – 43” or “34 a – c”.

So it’s quite messy…

I’m working in Europe (Germany) and here the street names come BEFORE the house number (as opposed to in English-speaking countries, where the reverse is true.)

So, I’m thinking whether I can tell a macro to cut and paste “everything before the first number in the cell” (this would be the street name) and to cut and paste “the first number in the cell and everything that comes after it” somewhere else.

Alternatively, if that’s too tricky, I could also get each word of the street name and each number / letter of the house number to be posted into separate cells – that way I could maybe tell a macro to check whether the contents of a cell are words or numbers, but I don’t really know if that would make it any less tricky.

Many thanks for any of your thoughts!

Leila-Marie
<!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Normale Tabelle"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
How about posting a SMALL sample of your data before and after the rquired cleansing.
 
Upvote 0
Have your tried text to columns? Theres a bunch of options in there. Without actually seeing the data its hard to know what would work.
 
Upvote 0
“everything before the first number in the cell” (this would be the street name) and “the first number in the cell and everything that comes after it” somewhere else.

Well, I'm really new as a poster here, but I love the puzzle of doing string-processing in Excel, and I don't shy-away from brute-force. These two formulae work for me:
Code:
=LEFT(CT32,MIN(IFERROR(FIND("0",CT32),LEN(CT32)),IFERROR(FIND("1",CT32),LEN(CT32)),IFERROR(FIND("2",CT32),LEN(CT32)),IFERROR(FIND("3",CT32),LEN(CT32)),IFERROR(FIND("4",CT32),LEN(CT32)),IFERROR(FIND("5",CT32),LEN(CT32)),IFERROR(FIND("6",CT32),LEN(CT32)),IFERROR(FIND("7",CT32),LEN(CT32)),IFERROR(FIND("8",CT32),LEN(CT32)),IFERROR(FIND("9",CT32),LEN(CT32)))-1)
and:
Code:
=RIGHT(CT32,LEN(CT32)-MIN(IFERROR(FIND("0",CT32),LEN(CT32)),IFERROR(FIND("1",CT32),LEN(CT32)),IFERROR(FIND("2",CT32),LEN(CT32)),IFERROR(FIND("3",CT32),LEN(CT32)),IFERROR(FIND("4",CT32),LEN(CT32)),IFERROR(FIND("5",CT32),LEN(CT32)),IFERROR(FIND("6",CT32),LEN(CT32)),IFERROR(FIND("7",CT32),LEN(CT32)),IFERROR(FIND("8",CT32),LEN(CT32)),IFERROR(FIND("9",CT32),LEN(CT32)))+1)
but I'm kind of an *** when it comes to maintainability....
 
Upvote 0
Hi :)

Sorry I didn't reply quicker - my workload had been beyond the usual level of stupid, for the last 24 hours...

I will paste some example data now:




<tbody>
</tbody>
1017001_436950989742494_2122639193_n.jpg


And I'd like the data to be tidied up by a macro, to eventually look like this:

998310_436951746409085_41691839_n.jpg
 
Upvote 0
As you can see, there's not much of a "pattern" to the data, except that the street name comes before the house number and that the street name is made up solely of letters, spaces and punctutation marks.

I was thinking I could tell a macro to move along the cell from left to right and every thing that is in the cell, before it hits the first "number" is the street name. Every thing that's left in the cell, once the street name is removed, is the "house number"...
 
Upvote 0
Haha - ignore the errors in the 2 tables above... I am soooo tired and over-worked right now... Making the stupidest typos, etc... I changed some of the data in the 2nd table, and didn't think to change the first table correspondingly... aaaaargh... :oops:
I need a holiday and/ or a drink....! (y)
 
Upvote 0
Well, I'm really new as a poster here, but I love the puzzle of doing string-processing in Excel, and I don't shy-away from brute-force. These two formulae work for me:
Code:
=LEFT(CT32,MIN(IFERROR(FIND("0",CT32),LEN(CT32)),IFERROR(FIND("1",CT32),LEN(CT32)),IFERROR(FIND("2",CT32),LEN(CT32)),IFERROR(FIND("3",CT32),LEN(CT32)),IFERROR(FIND("4",CT32),LEN(CT32)),IFERROR(FIND("5",CT32),LEN(CT32)),IFERROR(FIND("6",CT32),LEN(CT32)),IFERROR(FIND("7",CT32),LEN(CT32)),IFERROR(FIND("8",CT32),LEN(CT32)),IFERROR(FIND("9",CT32),LEN(CT32)))-1)
and:
Code:
=RIGHT(CT32,LEN(CT32)-MIN(IFERROR(FIND("0",CT32),LEN(CT32)),IFERROR(FIND("1",CT32),LEN(CT32)),IFERROR(FIND("2",CT32),LEN(CT32)),IFERROR(FIND("3",CT32),LEN(CT32)),IFERROR(FIND("4",CT32),LEN(CT32)),IFERROR(FIND("5",CT32),LEN(CT32)),IFERROR(FIND("6",CT32),LEN(CT32)),IFERROR(FIND("7",CT32),LEN(CT32)),IFERROR(FIND("8",CT32),LEN(CT32)),IFERROR(FIND("9",CT32),LEN(CT32)))+1)
but I'm kind of an *** when it comes to maintainability....

Hi GSKras,
I lurve the attitude :)
But I'm getting a syntax error, when I try that code... No idea why, as I'm so daft at macros... (I usually RECORD them, not write them... how embarassing... :oops: )
 
Upvote 0
Hi GSKras,
I lurve the attitude :)
But I'm getting a syntax error, when I try that code... No idea why, as I'm so daft at macros... (I usually RECORD them, not write them... how embarassing... :oops: )

Err, yes, tried them as FORMULAE now... not macros (even more embarassing...)
But still getting an error message.

ANY IDEAS, ANYONE...?
 
Upvote 0
I got close to the answer like I can split the number away from the cell but the names is the weird one here is what I have below:


Excel 2007
ABC
1German Str. 10bGerman Str.10b
2German 9 cGerman 99 c
3German 9German 99
Sheet1
Cell Formulas
RangeFormula
B1=MID(A1,1,FIND(" ",A1,FIND(" ",A1)+1))
B2=MID(A2,1,FIND(" ",A2,FIND(" ",A2)+1))
B3=MID(A3,1,FIND(" ",A3,FIND(" ",A3)+1))
C1=MID(A1, MIN(FIND({"0","1","2","3","4","5","6","7","8","9"}, A1 & 1234567890) ), 100)
C2=MID(A2, MIN(FIND({"0","1","2","3","4","5","6","7","8","9"}, A2 & 1234567890) ), 100)
C3=MID(A3, MIN(FIND({"0","1","2","3","4","5","6","7","8","9"}, A3 & 1234567890) ), 100)
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,011
Members
449,204
Latest member
tungnmqn90

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