+ Reply to Thread
Results 1 to 2 of 2

Extract date-based data; from single rows w/ date range to multiple rows w/ single dates

Hybrid View

  1. #1
    Registered User
    Join Date
    04-06-2016
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    1

    Extract date-based data; from single rows w/ date range to multiple rows w/ single dates

    Hi, appreciate if anyone can give some advise on this. Have searched the web but to no avail.
    I have attached a sample of the raw data and desired outcome.

    Hope this is feasible; preferably with use of formulas, but welcome VBA too.
    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,983

    Re: Extract date-based data; from single rows w/ date range to multiple rows w/ single dat

    VBA solution

    Sub List_days()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim rng As Range
    Dim InArr() As Variant
    Dim OutArr(1 To 1000, 1 To 4) As Variant
    Dim Lastrow As Long, r As Long, rr As Long, i As Date
    Dim sdate As Date
    
    Application.ScreenUpdating = False
    
    srow = 4 ' Start row of input data
    
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    
    ws1.Activate
    
    With ws1
        Lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
        Set rng = .Range(.Cells(srow, 1), .Cells(Lastrow, 5))
        InArr = rng
        rr = 0
        For r = 1 To UBound(InArr, 1)
            sdate = InArr(r, 4)
            For i = InArr(r, 4) To InArr(r, 5)
                rr = rr + 1
                OutArr(rr, 1) = InArr(r, 1)
                OutArr(rr, 2) = InArr(r, 2)
                OutArr(rr, 3) = 1
                OutArr(rr, 4) = sdate
                sdate = sdate + 1
            Next i
        Next r
    End With
    
    ws2.Activate
    
    With ws2
        .Cells(1, 1) = "ID"
        .Cells(1, 2) = "Type"
        .Cells(1, 3) = "Days"
        .Cells(1, 4) = "Date"
        Set rng = .Range(.Cells(2, 1), .Cells(rr + 1, 4))
        rng = OutArr
        Columns("A:D").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
         End With
         Columns("D:D").NumberFormat = "d-mmm-yy"
        
    End With
    
    Application.ScreenUpdating = True
    
    
    End Sub
    Attached Files Attached Files

+ 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: 1
    Last Post: 11-09-2014, 06:04 PM
  2. [SOLVED] Need a formula to sum for a date with multiple rows into a single row
    By killerthun in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-30-2014, 04:16 PM
  3. Select multiple rows and cells based on a single date
    By UTLee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-16-2013, 11:09 AM
  4. Replies: 10
    Last Post: 02-19-2013, 12:05 PM
  5. Replies: 0
    Last Post: 10-16-2012, 03:26 PM
  6. [SOLVED] Date Filter based on Cell Input - single date or range of dates
    By babaloo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-23-2012, 10:32 AM
  7. Delete multiple rows of data based on criteria in a single cell
    By slaga9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2011, 03:41 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