Excel VBA split row to column

I got an Excel with only one column A storing records of around 20K rows, I need to copy and split the 20K records to next columns (e.g. column B to ...Z), each column with 400 rows and last column will store the reminding.

Thinking an array may help but I don't know how, any expert here could help pls?? Thanks!
hkgalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ProfessorJimJamCommented:
Please use the following code


It asks you in input box the numbers of row to be the split and then the cell to start populating the

Sub SplitColumn()
    'Updateby20141106
    Dim rng As Range
    Dim InputRng As Range
    Dim OutRng As Range
    Dim xRow As Integer
    Dim xCol As Integer
    Dim xArr As Variant
    xTitleId     = "Solit"
    Set InputRng = Application.Selection
    Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type: = 8)
    xRow         = Application.InputBox("Rows :", xTitleId)
    Set OutRng   = Application.InputBox("Out put to (single cell):", xTitleId, Type: = 8)
    Set InputRng = InputRng.Columns(1)
    xCol         = InputRng.Cells.Count / xRow
    ReDim xArr(1 To xRow, 1 To xCol + 1)
    For i = 0 To InputRng.Cells.Count - 1
        xValue = InputRng.Cells(i + 1)
        iRow = i Mod xRow
        iCol = VBA.Int(i / xRow)
        xArr(iRow + 1, iCol + 1) = xValue
    Next
    OutRng.Resize(UBound(xArr, 1), UBound(xArr, 2)).Value = xArr
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ProfessorJimJamCommented:
please see attached workbook.

save it somewhere and select the whole data in the column which u want to split , then press Control and M in the keyboard it will run the macro and input box will pop and ask where is the range you want to split if you already had selected the data before running the macro then the range already will be in the input box and then click ok and then it will ask you by how many rows put 400 in your case and then click ok then it will ask where u want to paste that split data, just click in a next adjecent cell to your column and then it will populate the whole split columns and then simply you can delete the original column which you do not need.  

courtesy of  Kutools the original code.
0
hkgalAuthor Commented:
really thanks i am looking into the code, for these two rows I don't really understand the function:

         iRow = i Mod xRow
         iCol = VBA.Int(i / xRow)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Martin LissOlder than dirtCommented:
Let's assume that i = 21and xRow = 5

iRow = i Mod xRow
Mod returns the remainder when the first value (i) is divided by the second value (xRow) so the result is 1

iCol = VBA.Int(i / xRow)
VBA.Int gives the Integer portion of the division so the result of 21/5 is 4
0
hkgalAuthor Commented:
Nice and promt solution! Thank you!
0
ProfessorJimJamCommented:
you are welcome and thanks for the feedback.


Well explained Martin. thank you Martin
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.