From post:
http://www.excelforum.com/excel-gene...-new-post.html
PeterGriffin,
Welcome to the Excel Forum.
With your data in column A, beginning in row 1.
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).
Adding the Macro
1. Copy the below macro, by highlighting the macro 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. 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 SplitData()
Dim LR As Long, MaxCells As Integer, NC As Long, a As Long
NC = 2
With ActiveSheet
LR = .Cells(Rows.Count, 1).End(xlUp).Row
On Error GoTo ErrorRoutine
MaxCells = InputBox("Enter the maxium integer number of cells per column?")
If MaxCells >= LR Or MaxCells <= 0 Then
Exit Sub
Else
Application.ScreenUpdating = False
For a = MaxCells To LR Step MaxCells
.Range("A" & a + 1 & ":A" & a + MaxCells).Copy .Cells(1, NC)
NC = NC + 1
Next a
.Range("A" & MaxCells + 1 & ":A" & LR).ClearContents
End If
End With
Application.ScreenUpdating = True
Exit Sub
ErrorRoutine:
Application.ScreenUpdating = True
MsgBox "You did not enter an integer value - macro terminated!"
End Sub
Then run the "SplitData" macro.
Bookmarks