Solved

excel 2013

Posted on 2016-10-12
1
30 Views
Last Modified: 2016-10-14
I have two columns in excel, one for unique I'd and second total data,  in below example I would like to explain
I'D.   total data
12.     5
14.      60
18.     44

I would like to create 5 rows for I'd 12 with starting from 01.01.2016, 60 rows for I'd 14 with starting date from 01.01.2016, it should look like below
I'd.   date
12.    01.01.2016
12.    01.02.2016
12.    01.03.2016
12.    01.04.2016
12.   01.05.2016

how I can do that, I have many records that I want to create dates for that
0
Comment
Question by:snhandle
1 Comment
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
Comment Utility
If the original data was in columns A and B on the active sheet and started in row 2 this code will put the 'expanded' data in columns D and E.
Sub ExpandData()
Dim arrIn As Variant
Dim arrOut As Variant
Dim I As Long
Dim J As Long
Dim cnt As Long

    arrIn = Range("A2", Range("B" & Rows.Count).End(xlUp)).Value
    
    ReDim arrOut(1 To Application.Sum(Application.Index(arrIn, , 2)), 1 To 2)
    
    cnt = 1
    
    For I = LBound(arrIn) To UBound(arrIn)
        For J = 1 To arrIn(I, 2)
            arrOut(cnt, 1) = arrIn(I, 1)
            arrOut(cnt, 2) = DateSerial(2016, 1, 1) + J - 1
            cnt = cnt + 1
        Next J
    Next I
    
    Range("D1:E1").Value = Array("ID", "Date")
    
    With Range("D2").Resize(UBound(arrOut, 1), UBound(arrOut, 2))
        .Value = arrOut
        .EntireColumn.AutoFit
    End With
    
End Sub

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now