Forum Discussion
Need to restructure my data set. Any macro for this?
pbmc81in case you have too many territories for each date, you can run this macro. Just select the first date of your data and run the macro
Sub PREPARE_DATA()
' ------------------------
'SELECT FIRST DATE
XADDR = ActiveCell.Address
XROW1 = ActiveCell.Row
If Len(Cells(ActiveCell.Row + 1, ActiveCell.Column)) <> 0 Then
Selection.End(xlDown).Select ' MOVE TO BOTTOM OF THE LIST IF MORE THAN 1 ROW OF DATA
End If
XROW2 = ActiveCell.Row
XROWS = XROW2 - XROW1 + 1
XCOL = ActiveCell.Column
Range(XADDR).Select
XNEWROW = XROW2 + 4 ' row where your data will go
For I = XROW1 To XROW2
XDATE = ActiveCell.Value
Selection.Offset(0, 1).Select
While Len(ActiveCell.Value) <> 0
XTERRITORY = ActiveCell.Value
Cells(XNEWROW, XCOL) = XDATE
Cells(XNEWROW, XCOL + 1) = XTERRITORY
XNEWROW = XNEWROW + 1
Selection.Offset(0, 1).Select
Wend
Cells(ActiveCell.Row + 1, XCOL).Select
Next I
Cells(XROW2 + 4, XCOL).Select
' ------------------------
End Sub