+ Reply to Thread
Results 1 to 7 of 7

VBA Code to automatically change date and time format when pasting new data in a table

  1. #1
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    VBA Code to automatically change date and time format when pasting new data in a table

    Is there code I can use to automatically reformat data when pasting values from a large data-set into a table?

    Basically I have a dashboard that gets updated every week with thousands of records and for each event date, I need to use the "Replace All" function to remove the time from the end of the date in the event date column.

    The reason for this is because mu COUNTIFS formulas do not work with the standard export format however, it works perfectly with the format in the example below.

    Desensitised example attached including how the data is exported and the outcome I am looking for automatically in the table.

    Thanks
    Attached Images Attached Images
    Last edited by davo3286; 04-08-2019 at 03:17 PM. Reason: Extra Information

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Code to automatically change date and time format when pasting new data in a table

    Try using code like

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: VBA Code to automatically change date and time format when pasting new data in a table

    Hi Bernie,

    Thanks for the code, much appreciated! It doesn't seem to be doing the trick although I can see it is 'running' the code when I paste new data in.

    Even when manually formatting the cells to "dd-mm" etc. I am still required to manually remove the time and then "Replace All".

    Any other suggestions?

    Thanks

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Code to automatically change date and time format when pasting new data in a table

    Are you using a data connection? Or are you copying and pasting? If so, are you pasting values only, or formats as well? Can you share a workbook?

  5. #5
    Valued Forum Contributor
    Join Date
    11-02-2016
    Location
    NY
    MS-Off Ver
    2010
    Posts
    459

    Re: VBA Code to automatically change date and time format when pasting new data in a table

    If you pre-format the data to your desired format, then Copy & Paste as Values....it should work too!

  6. #6
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: VBA Code to automatically change date and time format when pasting new data in a table

    I have attached a desensitised example. The issue seems to be that even when using code or custom cell settings the time cannot be removed automatically and I am still required to use the "Replace All" function each time I update (and for all event dates). Thanks!
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Code to automatically change date and time format when pasting new data in a table

    This seemed to work on your example worksheet:

    Please Login or Register  to view this content.

+ 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] Change automatically Data Label & Vertical Axis format based on data value format
    By Neilesh Kumar in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 06-01-2018, 01:14 AM
  2. Code is erroneously copying and pasting the time format all over my workbook
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2017, 12:27 PM
  3. Need vba code to change date&time stamp as date format dd-mmm-yy in A:A rng
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2014, 06:08 AM
  4. Prevent change in cell format by pasting data
    By ssdhutekar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2014, 06:43 AM
  5. Prevent change in cell format by pasting data
    By ssdhutekar in forum Hello..Introduce yourself
    Replies: 2
    Last Post: 07-10-2014, 04:17 AM
  6. Replies: 8
    Last Post: 06-20-2014, 02:40 AM
  7. [SOLVED] help on vba code to change the error date format as standard format mm/dd/yyyy
    By johnodys in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-13-2013, 01:10 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