bigdan,
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 ReorgDataV3()
' stanleydgromjr, 09/14/2012
' http://www.excelforum.com/excel-general/860341-macro-for-copy-and-pasting-duplicates.html
Dim w1 As Worksheet, ws As Worksheet
Dim lr As Long, r As Long, n As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
lr = w1.Cells(Rows.Count, 1).End(xlUp).Row
For r = 1 To lr
n = Application.CountIf(w1.Columns(2), w1.Cells(r, 2).Value)
If Not Evaluate("ISREF(" & w1.Cells(r, 2).Value & "!A1)") Then Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = w1.Cells(r, 2).Value
Set ws = Worksheets(w1.Cells(r, 2).Value)
With ws.Cells(1, 1).Resize(, 3)
.Value = [{"Survey#","Question","Response"}]
.HorizontalAlignment = xlCenter
.Font.FontStyle = "Bold"
.Font.Size = 11
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlThin
End With
w1.Cells(r, 1).Resize(n, 3).Copy ws.Cells(2, 1).Resize(n, 3)
ws.Cells(n + 1, 1).Resize(, 3).Borders(xlEdgeBottom).Weight = xlMedium
ws.UsedRange.Columns.AutoFit
r = r + n - 1
Next r
w1.Activate
Application.ScreenUpdating = True
End Sub
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 ReorgDataV3 macro.
Bookmarks