Consulting

Results 1 to 5 of 5

Thread: How to extract date range into multiple rows?

  1. #1
    VBAX Regular
    Joined
    Nov 2015
    Posts
    43
    Location

    How to extract date range into multiple rows?

    I have a input file which have date range for 5,10,15 days. I would like to extract those date range into each single rows.
    See example below and attached INPUT.xls file . Can you guide me to write a VBA code. The original file contains more than thousand records .


    Input File
    =======

    ID------ from date----- TO Date
    ----------------------------

    1020---- 2/20/2016 ---- 2/22/2016



    Output File
    =======

    ID----- from date----- TO Date
    ---------------------------
    1020------2/20/2016---- 2/20/2016
    1020----- 2/21/2016---- 2/21/2016
    1020----- 2/22/2016----- 2/22/2016
    Attached Files Attached Files

  2. #2
    Try this.

    Sub PivotGuy()
        Dim arr1, arr2, c As Long, x As Long, y As Long
        With Worksheets("INPUT").Range("A1").CurrentRegion
            arr1 = .Offset(1).Resize(.Rows.Count - 1, 5).Value
            ReDim arr2(1 To WorksheetFunction.Sum(.Columns(4)), 1 To 5)
        End With
        y = 1
        For c = LBound(arr1, 1) To UBound(arr1, 1)
            For x = 1 To arr1(c, 4)
                arr2(y, 1) = arr1(c, 1): arr2(y, 2) = arr1(c, 2) + x - 1: arr2(y, 3) = arr1(c, 2) + x - 1
                arr2(y, 4) = 1: arr2(y, 5) = arr1(c, 5): y = y + 1
            Next x
        Next c
        Worksheets("OUTPUT").Range("A2").Resize(UBound(arr2, 1), UBound(arr2, 2)).Value = arr2
    End Sub
    Attached Files Attached Files

  3. #3
    VBAX Regular
    Joined
    Nov 2015
    Posts
    43
    Location
    Skywriter: Thanks you very much for your time and effort . It worked with no issue. I really appreciate your time. You rock.

  4. #4
    My pleasure, thanks for the feedback.

  5. #5
    Hi, Just to thank you again, this is exactly what I needed as well, many thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •