Splitting Columns in Excel

Posted by Nicole on October 21, 2009 in Development | No Comments

If you’re like me and get frustrated with Excel’s lack of column splitting, run this macro to split them.

Sub SingleToMultiColumn()
Dim rng As Range
Dim iCols As Integer
Dim lRows As Long
Dim iCol As Integer
Dim lRow As Long
Dim lRowSource As Long
Dim x As Long
Dim wks As Worksheet

Set rng = Application.InputBox _
(prompt:="Select the range to convert", _
Type:=8)
iCols = InputBox("How many columns do you want?")
lRowSource = rng.Rows.Count
lRows = lRowSource / iCols
If lRows * iCols <> lRowSource Then lRows = lRows + 1

Set wks = Worksheets.Add
lRow = 1
x = 1
For iCol = 1 To iCols
Do While x <= lRows And lRow <= lRowSource Cells(x, iCol) = rng.Cells(lRow, 1) x = x + 1 lRow = lRow + 1 Loop x = 1 Next End Sub

Leave a Reply

You must be logged in to post a comment.