• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to convert ungrouped data to raw data

gopikrishna

New Member
Suppose one has ungrouped data as

class Frequency

22 3

25 2

30 10


is there any macro or code available to convert the above to say


22

22

22

25

25 etc


Thanks
 
Interesting question Gopi.


You can use a macro to ungroup the data.


Assuming the grouped values in the range lstGroups and next column has frequencies,


Sub unGroupData()

'ungroup data in lstGroup

'ungrouped data starts in cell D2


Dim cell As Range

Dim lastCell As Range


'delete ungrouped data

Range(Range("D2"), Range("D2").End(xlDown)).ClearContents


Set lastCell = Range("D2")


For Each cell In Range("lstGroups")

Range(lastCell, lastCell.Offset(cell.Offset(, 1).Value - 1)).Value = cell.Value

Set lastCell = Range("D2").End(xlDown).Offset(1)

Next cell

End Sub


Please download this file to see the macro in action.


http://img.chandoo.org/playground/ungroup%20data%20gopi.xlsm
 
Back
Top