Solved

excel 2013

Posted on 2016-10-12
1
54 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 33

Accepted Solution

by:
Norie earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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