davet,
Welcome to the Ozgrid Forum.
Detach/Open workbook ReorgData Sp - davet - OZ161519 - SDG10.xlsm and run macro ReorgData.
If you want to use the macro on another workbook:
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
Option Explicit
Sub ReorgData()
' Stanley D. Grom, 01/17/2012
' [URL]http://www.ozgrid.com/forum/showthread.php?t=161519[/URL]
Dim w1 As Worksheet, wR As Worksheet
Dim lr As Long, r As Long, Sp, n As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
w1.UsedRange.Copy wR.Range("A1")
lr = wR.Cells(Rows.Count, 1).End(xlUp).Row
For r = lr To 1 Step -1
If InStr(wR.Cells(r, 2), ",") > 0 Then
Sp = Split(wR.Cells(r, 2), ",")
wR.Rows(r + 1).Resize(UBound(Sp)).Insert
wR.Cells(r, 2).Resize(UBound(Sp) + 1) = Application.Transpose(Sp)
wR.Cells(r, 1).Resize(UBound(Sp) + 1) = wR.Cells(r, 1)
End If
Next r
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub
Display More
Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm
Then run the ReorgData macro.