+ Reply to Thread
Results 1 to 8 of 8

Adding spaces between addresses

Hybrid View

  1. #1
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Adding spaces between addresses

    Hello. I have a problem with some data which is together like this:

    Brunkebergstorg9Stockholm103Sverige
    111KlaraÖstrakyrkogata7Stockholm52Sverige
    Drottninggatan8836StockholmSverige
    Brunkebergstorg9StockholmSverige10327

    All street number and ZIP codes are together with streetnames and city names.But I would like to get to this form:

    Brunkebergstorg 9 Stockholm 103 Sverige
    111 Klara Östrakyrkogata 7 Stockholm 52 Sverige
    Drottninggatan 8836 Stockholm Sverige
    Brunkebergstorg 9 Stockholm Sverige 10327

    Is it possible to make VBA code or something that which will but spaces to the text when he finds that letter and number is together?
    Last edited by HelpExc; 11-14-2012 at 06:32 PM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Adding spaces between addresses

    Between Stockholm and Sverige there is no number
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Adding spaces between addresses

    Quote Originally Posted by patel45 View Post
    Between Stockholm and Sverige there is no number
    Yes if possible it will also but space when he finds Capital letter.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Adding spaces between addresses

    perhaps
    Sub splitwordsandnumbers()
       Dim rCell             As Range
       Application.ScreenUpdating = False
       
       With CreateObject("vbscript.regexp")
          .Pattern = "(([0-9]+)|([A-Z]))"
          .ignorecase = False
          .Global = True
          For Each rCell In Selection
             rCell.Value = Application.Trim(.Replace(rCell, " $2 $3"))
          Next rCell
       End With
       Application.ScreenUpdating = True
    End Sub
    select the cells and then run the code
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Adding spaces between addresses

    My compliments !!!

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Adding spaces between addresses

    JP posted the same as I was working on. One minor addition to his excellent code I could suggest is to use this pattern...
    .Pattern = "(([0-9]+)|(\W))"

    It would add a space before all upper case characters not just A-Z.
    Example: Klara Östrakyrkogata

  7. #7
    Registered User
    Join Date
    11-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Adding spaces between addresses

    Thank you very for this solution, it works perfectly

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Adding spaces between addresses

    my pleasure :-)

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1