splitting long columns

R

richzip

I have a spreadhseet that has about 800+ rows (2 columns), which takes
several pages. I am convering this sheet to PDF. Is there a way, within
Excel, that I can automaticaly split after a set number of rows, copy the
data and paste it to the top of the page in different columns? This way
..intead of 2 column x 800 rows (and 15 pages), I would have 8 columns x 200
rows (and 4 pages).
 
G

Gary''s Student

Assuming your data is in cols A & B, try this small macro:

Sub Columnize()
n = Cells(Rows.Count, "A").End(xlUp).Row
k = 1
j = 1
For I = 1 To n
Set r = Range(Cells(I, 1), Cells(I, 2))
r.Copy Cells(k, j)
k = k + 1
If k = 201 Then
k = 1
j = j + 2
End If
Next
Range("A201:B" & n).Clear
End Sub
 
R

richzip

Thank you ..that works great!

Is there a way I can modify the macro so that it skips one column between
each pair that is copied?
 
G

Gary''s Student

Just a one line change:

Sub Columnize()
n = Cells(Rows.Count, "A").End(xlUp).Row
k = 1
j = 1
For I = 1 To n
Set r = Range(Cells(I, 1), Cells(I, 2))
r.Copy Cells(k, j)
k = k + 1
If k = 201 Then
k = 1
j = j + 3
End If
Next
Range("A201:B" & n).Clear
End Sub

In this version we bump j by 3 rather than 2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top