+ Reply to Thread
Results 1 to 3 of 3

Code for random spaces for text to column in VBA

  1. #1
    Registered User
    Join Date
    04-11-2014
    Location
    Phoenix, AZ
    MS-Off Ver
    MS Office 2010
    Posts
    8

    Code for random spaces for text to column in VBA

    I am sorting data using a Marcros program I designed, and in the city column there is the City,State, and Postal Code. I need them seperated into seperate columns so i was using txt to column. This worked very well, until there were spaces in the Cities. For instance, it would be Yorba Linda, CA 91542. This would seperate it using spaces and the city would now be in two seperate columns when it is supposed to be in one. I can't use the fixed width because there are a lot of different city names. So what would be the best VBA code to make this work? Thank you for any help

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Code for random spaces for text to column in VBA

    Before going down the VBA route, why not do two text to columns.
    First one splits on the comma so it if Yorba Linda, CA 91542 is in Column A and you split to A and B, then Yorba Linda would be in A and CA 91542 would be in B. Do a text to columns on Column B delimited with a space and then in B you have CA and in C you have 91542.

    If not satisfied with this, then post back and we can develop a VBA solution.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    04-11-2014
    Location
    Phoenix, AZ
    MS-Off Ver
    MS Office 2010
    Posts
    8

    Re: Code for random spaces for text to column in VBA

    wow, that is a great idea. I didnt even think about that. Thank you so much. thatll work perfectly

+ 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. shift cells in column 2 spaces to right if specific text appears in that column
    By hosburgh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2014, 12:46 PM
  2. remove random spaces in a text string
    By mariusescu in forum Excel General
    Replies: 2
    Last Post: 07-10-2008, 03:32 PM
  3. Replies: 4
    Last Post: 03-23-2008, 06:27 PM
  4. Delete empty spaces at the end of text of a column?
    By nbaj2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2006, 09:50 AM
  5. [SOLVED] Excel: replace all 2 spaces to FF/LR in column of text
    By Bill Craig in forum Excel General
    Replies: 4
    Last Post: 06-07-2006, 12:45 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