+ Reply to Thread
Results 1 to 5 of 5

VBA > Loop Help > Copy, Paste, Format Date - Is there a better way to do this?

  1. #1
    Registered User
    Join Date
    03-23-2015
    Location
    Austin, Texas
    MS-Off Ver
    2016
    Posts
    11

    VBA > Loop Help > Copy, Paste, Format Date - Is there a better way to do this?

    All,


    Situation: Very large list of dates in column A (approximately 300-400K values) formatted as "m/d/yyyy h:mm"
    Desire: Way to paste these values in Bx, Cx, and Dx each with different format for each value of x until row count.
    Issue: My code literally takes 30 minutes and this step is just the first part of the code for the complete macro
    Question: Is there a better way to write my code that it doesn't take so long? I'm pretty sure it's inefficient.

    Bonus: I'd like to just delete the original date column once all is said and done with the loop automatically.

    Example of what I'd like to accomplish:
    For x = 2 to row count
    Given A2 = 11/1/2018 8:59:59 AM (m/d/yyyy h:mm)
    Make B2 = Nov-2018 (mmm-yyyy)
    Make C2 = Nov-01 (mmm-dd)
    Make D2 = 8:00 AM (needs to be rounded down to the nearest whole hour)

    Please Login or Register  to view this content.
    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA > Loop Help > Copy, Paste, Format Date - Is there a better way to do this?

    Try this

    Please Login or Register  to view this content.
    Last edited by mikerickson; 01-20-2019 at 07:11 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    03-23-2015
    Location
    Austin, Texas
    MS-Off Ver
    2016
    Posts
    11

    Re: VBA > Loop Help > Copy, Paste, Format Date - Is there a better way to do this?

    Thank you! It does work - my question is would you be so kind as to explain the logic? My only issue is that I had hoped to build around this code the ability to basically import the spreadsheet that actually contains those dates into sheet two, column D and then use sheet one as for the final spreadsheet once all is said and done.

    Is it possible to re-reply with a version of the code for just one date so I could understand it better? it does work though! Thank you so much! It's fast too.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA > Loop Help > Copy, Paste, Format Date - Is there a better way to do this?

    This version shows how to do the rounding/truncation.

    Mike does great work. He used the R1C1 format. Enable it by File > Options > Formulas > R1C1. Then put =RC1 in cell to right where you want the R1C1 formula to get the value of 1 column to left.

    Please Login or Register  to view this content.
    Last edited by Kenneth Hobson; 01-20-2019 at 07:42 PM.

  5. #5
    Registered User
    Join Date
    03-23-2015
    Location
    Austin, Texas
    MS-Off Ver
    2016
    Posts
    11

    Re: VBA > Loop Help > Copy, Paste, Format Date - Is there a better way to do this?

    That makes sense. Thanks guys! I like actually learning the code and reasoning behind the code I appreciate that!

+ 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. Looking To Sort Data To Separate Worksheets Based On Date
    By jsmith2018 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2018, 04:02 PM
  2. [SOLVED] copy range & paste every 3rd row after endlast row loop till date reach 31/11/2014 in colA
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2014, 06:58 AM
  3. Replies: 1
    Last Post: 07-19-2014, 04:05 AM
  4. Copy, Paste loop based on today's Date
    By oscarmiike in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-22-2014, 09:05 PM
  5. How to copy and paste date but maintaining the date format using macros
    By Wanjama in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-16-2014, 09:03 AM
  6. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  7. Date format macro and copy paste
    By Libster78 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2010, 11:08 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