?
Solved

excel 2013

Posted on 2016-10-12
1
Medium Priority
?
61 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 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 41841170
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

864 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