bugsyb6,
Stan - Looking at your code (and trying to learn from it), it appears that it counts the number of commas in the cell in column E and then inserts that many rows. The part I'm not sure about is how does it know what to delete from each row after it copies the original data into the new rows?
See below in bold an explanation of the lines of code:
Option Explicit
Sub ReorgData()
' stanleydgrom, 02/07/2011
' http://www.vbaexpress.com/forum/showthread.php?t=36040
Dim LR As Long, a As Long, Sp, Sp2
Application.ScreenUpdating = False
With Worksheets("Sheet1")
LR = .Cells(Rows.Count, 1).End(xlUp).Row
For a = LR To 2 Step -1
' Lets use cell E7 as an example
' If there are any , characters
If InStr(.Cells(a, 5), ",") > 0 Then
' Sp is an array, in this case the array contain 5 elements,
' Sp(0) thru Sp(4)
Sp = Split(Trim(.Cells(a, 5)), ",")
' The upper bound of array Sp is Sp(4)
' So we insert 4 rows in/at row 8
.Rows(a + 1).Resize(UBound(Sp)).EntireRow.Insert
' This is copying A7:G7 to A8:G11
.Range("A" & a + 1 & ":G" & a + 1).Resize(UBound(Sp)).Value = .Range("A" & a & ":G" & a).Value
' Change the format of the cells in range E7:E11 to text
.Range("E" & a).Resize(UBound(Sp) + 1).NumberFormat = "@"
' Transpose the Sp array into range E7:E11
.Range("E" & a).Resize(UBound(Sp) + 1).Value = Application.Transpose(Sp)
' The next three lines of code splits the data in cell F7
' and then transpose the Sp2 array into range F7:F11
Sp2 = Split(Trim(.Cells(a, 6)), ", ")
.Range("F" & a).Resize(UBound(Sp2) + 1).NumberFormat = "@"
.Range("F" & a).Resize(UBound(Sp2) + 1).Value = Application.Transpose(Sp2)
End If
Next a
LR = .Cells(Rows.Count, 1).End(xlUp).Row
.Range("E2:E" & LR).Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End With
Application.ScreenUpdating = True
End Sub
Hope this helps you understand what is going on.
Have a great day,
Stan