+ Reply to Thread
Results 1 to 19 of 19

Macro to format exported names

  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Post Macro to format exported names

    I have a Macro that I pulled through various sources and am stuck at the final piece of the code to get it it do what I want. I was hoping a second pair of eyes can help me here. Originally I tried recording the text to column application and modifying that however, that turned out to be more complicated.

    The goal of the Macro is to Format both columns Q & T so they simply read "FirstName LastName". The formula for Column Q works, however I found that it will not work for Column T because their is no comma(,) in the formatting of this column of Data.

    Since this data is coming via export, I have no control over the format. The Macro is attached to the sample data on the spreadsheet below and you will see what I mean when you run it initially. Any thoughts on how I can get this to work?

    Also ideally having the column references to go by NAME vs Column letter would be great, but if too great, it would still be a huge win to get the formatting of Column T working.


    SAMPLE DATA w Macro Sample Data 4.xlsm

    Desired DATA OUTPUT Sample Data 4 OUTPUT.xlsm
    Last edited by slick9456; 08-16-2014 at 06:07 AM. Reason: Included desired output

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

    Re: Macro to format exported names

    I did not understand, can you attach a file with desired output ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to format exported names

    Hi, slick9456,

    maybe replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Macro to format exported names

    Hi HaHoBe, I tried replacing the code with what you advised, the output data in that column comes out as:

    "LastName First Name M." whereas I still need the data in Column T to mirror the format in Column Q as "FirstName LastName"

  5. #5
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Macro to format exported names

    Quote Originally Posted by patel45 View Post
    I did not understand, can you attach a file with desired output ?
    I have attached a Sample Output sheet as requested.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to format exported names

    Hi, slick9456,

    did you try out the suggestion I supplied in post #3 with replacing the formula to use for Column V?

    Ciao,
    Holger

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

    Re: Macro to format exported names

    did you try HaHobe solution ?

  8. #8
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Macro to format exported names

    Quote Originally Posted by HaHoBe View Post
    Hi, slick9456,

    did you try out the suggestion I supplied in post #3 with replacing the formula to use for Column V?

    Ciao,
    Holger
    EDIT: I did, it comes out in the format "LastName FirstName M." which is different than how Column Q is output (my goal) "FirstName LastName"
    Last edited by slick9456; 08-16-2014 at 06:44 AM. Reason: clarification

  9. #9
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Macro to format exported names

    Quote Originally Posted by HaHoBe View Post
    Hi, slick9456,

    did you try out the suggestion I supplied in post #3 with replacing the formula to use for Column V?

    Ciao,
    Holger
    I did try your solution, here's an attached output after applying your suggestion. It seems its off just a little, I would still want the data in Column T(Formula V) to match how column Q comes out in the format "FirstName LastName

    HAHOBE OUTPUT ->HaHoBe OUTPUT.xlsm

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro to format exported names

    Hi, slick9456,

    as you are posting in the VBA forum I wonder why you would need an extra long Formula instead of using some VBA code and a slightly simpler formula to get the very same result.

    Replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    and you could omitt the replacement for that column thereafter as well.

    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Macro to format exported names

    Hi Holger,

    I wasn't sure where to post the since the issue stems from the macro. Per the formula you provided it seems that this line is referencing the specific ID I placed in the sample data:

    Please Login or Register  to view this content.
    However this won't work in the broader sense because you are referencing a specific instance of an ID (00900123123) which will be unique for each employee in my company, so this number can be completely different per each row of data. I also wanted to remove the Middle Initial and period from their names in the process so that it truly only reads as First Last and nothing else.

    Which is why the first function works so well because it will work for any variation of data, as long as it maintains the same format. However I just need to modify that to since I found out that the format of the data in Column T is different than from Column Q in that the data in Column T does not have a (,) which is partially what the original formula searches for to work.

    I am open to any simpler variation of a formula to work, but the goal would be to have it be able format the data in that column regardless of name length or ID # to get it in the format First Last.

    Sorry for the confusion.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Macro to format exported names

    Not sure if this is resolved, but I think this will do the job:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  13. #13
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Macro to format exported names

    Hi Trevor,

    I just tested this on my sample data and I think this is what I am looking for. I will test with some real data shortly and post my results.


    Thanks!

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

    Re: Macro to format exported names

    Try this too,
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    03-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Macro to format exported names

    Wow, this works as well jindon. Just curious how this varies from the code TMS provided as from looking at yours, it seems more compact and as column positions may change in the future, this seems easier to update the column references for, in the event of any shift.

    Quote Originally Posted by jindon View Post
    Try this too,
    Please Login or Register  to view this content.

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Macro to format exported names

    It is indeed much more compact. Don't you just love Regular Expressions!? I think I'm going to have to spend some time playing with them as I really struggle to get my head round it. Effectively, it still has to process the same number of cells but I suspect it will be quicker than mine.

    If the columns are likely to change and/or there might be more of them, I'd change my code to use column references and loop through the columns.

    With stuff like this, particularly for clients, I'd use a Configuration sheet which could be used to list the columns to be processed (either in separate cells or as a comma separated string in one cell).

    Regards, TMS

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

    Re: Macro to format exported names

    Used Regular Expressions which allows you to recall and manipulate matching substring of pattern matching.

    In this case, you want "First Last" from
    "Last, First M. (00900123123)"
    or
    "Last First M. (00900123123)"

    Logical matching is
    1) Block of characters from the beginning that excludes comma and space.
    gives you "Last"

    2) Block of characters after 1) that excludes sapce.
    gives you "First"

    Then swap the order of 1) and 2)

    That's what the code is doing.

  18. #18
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Macro to format exported names

    @jindon:
    That's what the code is doing.
    Easy for you to say.
    Please Login or Register  to view this content.
    just looks like a censored profanity (OK, maybe it is )


    Regards, TMS

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Macro to format exported names

    Improved version; more easily tailored and less repetitive.

    Please Login or Register  to view this content.

    Regards, TMS

+ 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] Date formula - Change Format to YYYYMMDD from Exported Format
    By haleakala17 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-21-2014, 03:22 PM
  2. [SOLVED] Can you use a Macro to auto format a MS Access Report (exported to Excel)?
    By Castillb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-07-2013, 12:43 PM
  3. VBA to Format Exported Excel Data
    By rlsublime in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 04-04-2012, 09:25 PM
  4. Exported Date Format is Changed by Ecxcel
    By Neil10365 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2005, 07:05 PM
  5. Date Format exported from Access
    By Nuttychick in forum Excel General
    Replies: 0
    Last Post: 05-09-2005, 06:54 AM

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