+ Reply to Thread
Results 1 to 9 of 9

VBA code for location string split

  1. #1
    Registered User
    Join Date
    04-21-2020
    Location
    toronto
    MS-Off Ver
    2017
    Posts
    23

    VBA code for location string split

    Hi guys,

    I am trying to write a script which populates a bigger data set from the original sheet to created template ("proforma").

    I am okay with most of it, however, there is a part that I struggle with - the location split.

    While in the original sheet the location is placed in one column ( yet includes two types of 3 string address, which slightly differ in terms of deliminator as one type contains a street and one type classic - city, region, country format) the proforma sheet needs to accommodate the split of both types of addresses.

    Attached is the sample of data - Please note the split in the street address instances (where street address is given) as the zip code field and the street input have to be populated in separate columns. The second type of input i.e. city,region,country entry also requires split and subsequent input in different cells.

    Please note that all string inputs (placed in distinct cells) have to be on a separate line.


    Thank you very much for looking into this.

    Kind regards,

    Velehrad
    Attached Files Attached Files
    Last edited by Velehrad; 05-01-2020 at 10:26 PM.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,002

    Re: VBA code for location string split

    .
    Are you familiar with TEXT TO COLUMNS, located on the DATA TAB ?

    When selecting the DELIMITERS you can choose OTHER and type in that symbol ~

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: VBA code for location string split

    Quote Originally Posted by Logit View Post
    .
    Are you familiar with TEXT TO COLUMNS, located on the DATA TAB ?
    As far as I can tell, the delimiters are not simple enough to allow TEXT TO COLUMNS to be used.



    Quote Originally Posted by Velehrad View Post
    I am trying to write a script which populates a bigger data set...
    I think this macro will do what you want (it takes data from the "Original" worksheet and outputs to the blank "Split" worksheet)...
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 05-01-2020 at 11:55 PM.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,002

    Re: VBA code for location string split

    .
    That is a great macro ! I'll add it to my toolbox.
    Last edited by Logit; 05-02-2020 at 11:12 AM.

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: VBA code for location string split

    @Logit,

    I am not sure how great my macro is (after all, you did not click the asterisk/star icon ), but the code seems to me to be quite narrowly focused for something that one would want to add to one's toolbox.

  6. #6
    Registered User
    Join Date
    04-21-2020
    Location
    toronto
    MS-Off Ver
    2017
    Posts
    23

    Re: VBA code for location string split

    Hi Ricky,

    Thank you so much for your reply!

    I ran the macro and it works almost fine as some of the postcodes are still populated in the field of the "City" instead.

    Would there be a way to correct this? Also, how would I make the split more proper; i.e. populating the whole string (of street address as well as "city, region, country" only) to relevant fields?

    Attached please find the updated sheet including the application of the above code for better illustration.

    Would there be any way to cater for all variances of the Address structure?

    Many thanks.
    Attached Files Attached Files

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,002

    Re: VBA code for location string split

    .
    OK Rick ... I've stroked your ego by adding a "Thank You".

    I still think it is good work nevertheless ...


    Stay healthy my friends !

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: VBA code for location string split

    Try
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 05-03-2020 at 04:09 AM. Reason: Edited 2 lines,

  9. #9
    Registered User
    Join Date
    04-21-2020
    Location
    toronto
    MS-Off Ver
    2017
    Posts
    23

    Re: VBA code for location string split

    Hi Jindon,

    Once again, thank you so much...

    I have tried to use the above code, however, since the input is free text the code eventually breaks due to mismatch of structure as defined by regx..

    Could you please let me know a simple way to split the free text (location including street not starting with "~") in a separate column (street)? this input would only be used to determine the country (which is mandatory) while the rest would be put in one column (i.e. "street"). The rest should be split as per above; i.e. country, region, city.

    Many thanks,

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VBA code to Split and Sort String Values
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2020, 02:46 AM
  2. Replies: 4
    Last Post: 04-05-2016, 12:19 AM
  3. [SOLVED] Split String at every "/" then put split string results into a multiline textbox.
    By Andrew Andromeda in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2015, 01:49 AM
  4. [SOLVED] VBA code required to TRIM and SPLIT the selected Range (String)
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2015, 04:04 AM
  5. Replies: 1
    Last Post: 04-12-2014, 04:03 PM
  6. VB Code to split the text String
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-25-2013, 10:21 AM
  7. [SOLVED] How to split this long string code in multiple line to avoid an error???
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-24-2013, 10:08 PM

Tags for this Thread

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