+ Reply to Thread
Results 1 to 10 of 10

Manipulating date values

  1. #1
    Registered User
    Join Date
    12-28-2010
    Location
    Atlanta, GA
    MS-Off Ver
    2003 and 2010
    Posts
    27

    Manipulating date values

    Hey everyone,
    I have a question. I just started a new job, and for the past 10+ years they have manually been inputting post logs of when commercials ran, because nobody can figure out the bulk upload feature. Well... I'm lazy and don't want to manually input these logs... so I'm figuring it out.

    Here is the only problem I am experiencing at the moment. I get the logs in 3 different formats. The date has to be formatted as YYYYMMDD (i.e. 20110101 for Jan 1st 2011) I currently get it stored as text as 01/01, stored as text as Jan 01, and stored as text as 01/01/2011 8:35 pm (date and time in one cell).

    How can I write a macro to transform date as a text value into a date format? Thank you so much!

  2. #2
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Manipulating date values

    Can you post a sample workbook?
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Manipulating date values

    There's an old trick that may work for you.

    1) Highlight the column of dates (1 column only for this to work)

    2) Select Data > Text To Columns > Next > Next

    3) On the 3rd page of the wizard in the upper right corner is the Column Data Format options. Select Date: and choose the correct DMY, YMD, MDY, whatever from the drop down

    4) Click Finish and this usually allows Excel to convert the text values to proper dates.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    12-28-2010
    Location
    Atlanta, GA
    MS-Off Ver
    2003 and 2010
    Posts
    27

    Re: Manipulating date values

    Thanks for the feedback. Here is a sample workbook.

    The first tab shows an example of one log I get from a company, the column headers highlighted are those needed to populate the second sheet.

    The second tab shows the format it has to be placed in to upload. These highlighted cells are also the ones that need to be populated from the sheet the station gives me.

    Also, some are in 24 hour format, some are in AM/PM. I need it to be in 24 hour format.

    Thanks!
    Attached Files Attached Files
    Last edited by RussellNonBrand; 01-25-2011 at 10:53 AM.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Manipulating date values

    Drop the data into sheet1 then run this macro:
    Please Login or Register  to view this content.

    You will have a sheet you can save a CSV file and it will have the data in the correct spots/format.
    Last edited by JBeaucaire; 01-25-2011 at 01:16 PM.

  6. #6
    Registered User
    Join Date
    12-28-2010
    Location
    Atlanta, GA
    MS-Off Ver
    2003 and 2010
    Posts
    27

    Re: Manipulating date values

    THANKS! That is awesome! The only question I have is the date and time need to be split into two different cells... that macro puts them into one cell. Thank you!

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Manipulating date values

    Ah, I couldn't for the life of me figure out where the values in the Air Time column came from....duh!

    I've updated the macro above to fix that and include it.

  8. #8
    Registered User
    Join Date
    12-28-2010
    Location
    Atlanta, GA
    MS-Off Ver
    2003 and 2010
    Posts
    27

    Re: Manipulating date values

    lol that's quite alright! Thank you! So just curious... where did you learn to write this stuff? I consider myself very fluent in everything else within Excel, but I haven't ever gotten into macros beyond just recording my actions.

  9. #9
    Registered User
    Join Date
    12-28-2010
    Location
    Atlanta, GA
    MS-Off Ver
    2003 and 2010
    Posts
    27

    Re: Manipulating date values

    Hey man, two more questions for you.

    One is how do I write it so it only takes the left 13 characters of a cell? For the tape code, I need it to omit the -1234 on the end.

    Also, can I write a vlookup into it, so for example if it finds "ANPL" it will replace it with "APL"?

    I just enrolled in a VBA course next month, so hopefully I'll be able to start helping people here soon! Thank you!

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Manipulating date values

    The macro recorder is a great place to start.

    You can use the recorder to create a macro that:

    1) Does a global search and replace, search for ANPL and replace that with APL, in column H, yes?

    2) Inserts a LEFT() formula in J2 taking the 13 characters from K2. Then copy that down, then copy the new values and PASTESPECIAL > VALUES over the original K values, then delete the formulas in column J.

    I started learning macros by recording things, then posting the macros for "optimization", then learning by comparing what the pros did to my recorded macros to make them faster/better.

+ 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