Results 1 to 5 of 5

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

Threaded View

  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)

    Sub DateCopy()
    
    Dim lastrow As Long
    Dim x As Integer
    Dim y As Date
    
    Range("B1") = "MONTH-YEAR"
    Range("C1") = "MONTH-DAY"
    Range("D1") = "TIME"
    
     With Worksheets("Sheet1")
        lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
        
        For x = 2 To lastrow
        
            Range("A" & x).Copy Range("B" & x)
            Range("B" & x).NumberFormat = "mmm-yyy"
            Range("A" & x).Copy Range("C" & x)
            Range("C" & x).NumberFormat = "mmm-dd"
            Range("A" & x).Copy Range("D" & x)
            Range("D" & x).NumberFormat = "[$-en-US]h:mm:ss.000 AM/PM"
            
        Next x
        
     End With
    
    End Sub
    Thank you!
    Attached Files Attached Files

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