+ Reply to Thread
Results 1 to 10 of 10

Insert comma to change data format

  1. #1
    Registered User
    Join Date
    08-23-2024
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Insert comma to change data format

    I'm very new to macros but I have a problem that's probably pretty easy for some of you on here. I have several spreadsheets with approximately 100 rows and columns each. Some of the columns are supposed to be formatted as dates but they are entered as text (ex, Jan 05 2023 8:24 AM). I can't sort as a date in this format and changing the format to "Date" doesn't work. I found that when I add a comma between the day and year (05 and 2023 in my example) the cell converts to date format.

    I think I need a macro to look for all cells in this format (3 text characters then a blank and 2 numbers) and insert a comma into the 7th position.

    Can somebody help me out or offer a simpler approach?

    Thanks in advance.

    Sample data.xlsx
    Last edited by ST8GUY; 08-23-2024 at 03:24 PM.

  2. #2
    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
    48,996

    Re: Insert comma to change data format

    Welcome to the forum.

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    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


  3. #3
    Registered User
    Join Date
    08-23-2024
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: Insert comma to change data format

    Thanks TMS. I edited my original post and added a small sample of the data

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,525

    Re: Insert comma to change data format

    I used a formula like =VALUE(REPLACE(B1,7,1,", ")) and that converted all of the text dates in your example to date numbers. I think that should work as long as ti replacement always needs to occur at the 7th position in the text string, and the rest of the date string matches what your system expects for date+time text.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    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
    48,996

    Re: Insert comma to change data format

    Personally, I’d use a formula and copy and paste the values.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Format as date/time.

    And, if I was using VBA, I'd just drop that formula in a cell and convert the results to text

  6. #6
    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
    48,996

    Re: Insert comma to change data format

    Oddly, when I moved the file over to my laptop, the formula that I suggested would not work. Nor would MrShorty's solution. Very strange, as it seemed happy enough on my iPad. Anyway, a little rework and we have these options:

    Single cell, copied down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    SPILL formula (no need to copy):
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    And, VBA to implement the last formula:

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    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
    48,996

    Re: Insert comma to change data format

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: Insert comma to change data format

    Perhaps...Unless I am missing something...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  9. #9
    Registered User
    Join Date
    08-23-2024
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: Insert comma to change data format

    Thanks everyone. I used the formula from TMS. I wasn't able to get the VBA to work but it was likely a mistake on my part. I'm going to keep playing with that but I'm going to mark this as solved.

    Thanks again.

  10. #10
    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
    48,996

    Re: Insert comma to change data format

    You're welcome.



    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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] Cannot change format of scientific value on Microsoft Excel Comma Separated Values File
    By saudi_red_neck in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-26-2022, 05:22 AM
  2. [SOLVED] Group & concatenate data in comma seperated format
    By aashishni in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-19-2018, 08:29 AM
  3. Replies: 9
    Last Post: 04-09-2018, 09:46 PM
  4. macro to format data label, and add comma and percentage
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2015, 05:37 AM
  5. Replies: 21
    Last Post: 02-03-2014, 02:43 PM
  6. [SOLVED] Macro to change data entered in a cell seperated by a comma, into a vertical list of data
    By jholly3 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-13-2012, 03:51 PM
  7. Replies: 0
    Last Post: 04-10-2006, 05:10 AM

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