I have a giant spreadsheet that I inherited, and I would like
to change the data structure. I would like to have each record
(row) correspond to one date; currently it is set up with a
beginning and end time period. I think an example makes clear
what I’m hoping to do. Does anyone have a suggestion as to a
relatively efficient way to go about this?
Sorry about the previous content-less response. Clicked on the wrong
button. :-(
I think this is easiest to do with a macro, although an Excel solution might
be possible (TBD). The following macro assumes that the active worksheet
has the original data starting in A2
2. It creates a new worksheet with
reformatted data starting in A2:C2.
Do you need help entering and customizing the macro?
Would you prefer to select the original data (put the cursor in the
upper-left corner) and create the reformatted data in starting in the same
relative location on a new worksheet?
Sub doit()
Dim v As Variant
Dim nv As Long, r As Long, i As Long, j As Long
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
v = Range("a2", Cells(2, "d").End(xlDown))
nv = UBound(v, 1)
Sheets.Add after:=ActiveSheet
r = 1
For i = 1 To nv
For j = v(i, 3) To v(i, 4)
r = r + 1
Cells(r, "a") = v(i, 1)
Cells(r, "b") = v(i, 2)
Cells(r, "c") = j
Next j
Next i
With Application
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
MsgBox "done"
End Sub
----- original message -----
I have a giant spreadsheet that I inherited, and I would like to change the
data structure. I would like to have each record (row) correspond to one
date; currently it is set up with a beginning and end time period. I think
an example makes clear what I’m hoping to do. Does anyone have a suggestion
as to a relatively efficient way to go about this? Any ideas would be much
appreciated.—Dan
Name Location Begin End
A XX 1 3
A YY 4 6
A ZZ 7 7
B UU 3 5
B VV 6 7
Name Location Date
A XX 1
A XX 2
A XX 3
A YY 4
A YY 5
A YY 6
A ZZ 7
B UU 3
B UU 4
B UU 5
B VV 6
B VV 7