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
Solved

excel 2013

Posted on 2016-10-12
1
51 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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…

839 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