+ Reply to Thread
Results 1 to 2 of 2

Adding date parts to separate columns

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2011
    Location
    East Coast
    MS-Off Ver
    Office 365
    Posts
    33

    Adding date parts to separate columns

    Hello,

    The code below copies the 1st 5 columns from my Source Worksheet and appends them to a Target Worksheet.

    I actually have 2 questions:

    1) Once these rows are appended, I need to write out the Day, Month, Month Name, and Year of a date field (in Column 'E') into their own columns (Column 'F' thru Column 'I'). I found this code using a nifty Array, but I can't seem to get it to write the Day/Month/etc. values for just those newly-appended rows in Column 'F' thru Column 'I' (I need to make sure that any rows already present in the Target worksheet are not altered... only the newly-appended rows).

    2) What is the proper VBA to obtain the Month Name (in full Name format, e.g. 'December')? The 'MonthName' function doesn't work as I wrote it below.


    Thank you!!


    Set src = ThisWorkbook.Worksheets("Webstats_RptList_RawData")
    Set trg = ThisWorkbook.Worksheets("RptData_Cleaned")
    
    With Intersect(src.Range("A:E"), src.UsedRange).Offset(1).Resize(src.UsedRange.Rows.Count - 1)
        .Copy Destination:=trg.Range("A" & Rows.Count).End(xlUp).Offset(1)
        '.Delete
            With trg.Range("E??", trg.Range("E" & Rows.Count).End(xlUp))
             With .Columns("F:I")
                .Formula = Array("=Day(E??)", "=Month(E??)", "=MonthName(E??)", "=Year(E??)")
                .Value = .Value
             End With
        End With
    End With

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Adding date parts to separate columns

    try
        Dim src As Worksheet, trg As Worksheet, LastR As Range, temp As String
        Set src = ThisWorkbook.Worksheets("Webstats_RptList_RawData")
        Set trg = ThisWorkbook.Worksheets("RptData_Cleaned")
        Set LastR = trg.Range("a" & Rows.Count).End(xlUp)(2)
        With Intersect(src.Range("A:E"), src.UsedRange).Offset(1).Resize(src.UsedRange.Rows.Count - 1)
            .Copy LastR
            '.Delete
            temp = LastR(, 5).Address(0, 0)
            With LastR(, 6).Resize(.Rows.Count, 4)
                .Formula = Array("=day(" & temp & ")", "=month(" & temp & ")", _
                            "=text(" & temp & ",""mmmm"")", "=year(" & temp & ")")
                .Value = .Value
            End With
        End With

+ 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. Replies: 11
    Last Post: 12-16-2015, 11:30 AM
  2. Search parts of columns looking for matches in parts of other columns in a row
    By autiger58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2014, 03:52 AM
  3. Displaying parts of table in a separate worksheet.
    By SpreadtheSheet in forum Excel General
    Replies: 1
    Last Post: 06-10-2013, 09:11 PM
  4. Adding minutes and seconds in separate columns
    By excel2007student in forum Excel General
    Replies: 4
    Last Post: 10-08-2011, 07:57 AM
  5. Invoice with separate parts and labor totals
    By Jhor in forum Excel General
    Replies: 4
    Last Post: 07-08-2011, 10:44 AM
  6. Adding Time Values from Separate Hours and Minutes Columns
    By jeepers in forum Tips and Tutorials
    Replies: 2
    Last Post: 08-23-2005, 12:05 PM
  7. Split Number into Four Separate Parts
    By Gos-C in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-16-2005, 02:08 PM

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