Wrapping column of data into multiple columns

gir42

New Member
Joined
Apr 4, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I watched a Mr. Excel video showing how to use a Macro to take data in excel spreadsheet and cause it to populate into multiple columns for the purpose of printing full pages of data. I tried to modify the code to work for:
single column of about 600 words
using no header or column heading ( start in first row with data)
Want a full page which in my case would be 5 columns of 25 rows.

the macro worked for the first column (column 4) , the second column (column 5) but on the third set of 25 rows it populated at the end of column 4 instead of starting at row 1 in column 6. Can someone please help me with the code so I can get 5 columns of 25 words per page? My code is attached as a png. I applogize in advance if I am posting incorrectly. First time and not a power user!
thanks
gene
 

Attachments

  • macro-Mr.Excel.png
    macro-Mr.Excel.png
    31.6 KB · Views: 16

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
test-Macro-Wordle.xlsm
ABCDE
1abackabackamber
2abaseabaseample
3abateabateangry
4abbeyabbeyantic
5aboveaboveaorta
6abyssabyssaphid
7acuteacuteapple
8admitadmitapply
9adobeadobeapron
10adoptadoptaptly
11adoreadorearbor
12agapeagapeargue
13agateagatearoma
14agreeagreeaside
15aheadaheadaskew
16albumalbumasset
17alienalienatoll
18alikealikeatone
19allowallowaudit
20aloftaloftavail
21alonealoneavert
22aloudaloudawake
23alphaalphaawful
24altaraltaraxiom
25alteralterbadge
26amberbadlybluff
27amplebakerblurb
28angrybanalblurt
29anticbasicblush
30aortabatonbooby
31aphidbattyboost
32applebayoubooze
33apply beadyboozy
34apronbeefybough
35aptlybeginbraid
Sheet1
 
Upvote 0
Hello,
just wondering if I uploading sufficient data for you to see the problem.
 
Upvote 0
Hello @gir42. Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

Please try the following macro.

But before, create a sheet called "Output", in this sheet will be the result.
In the sheet "h1" put your data, rename in the macro "h1" and "output" by the names you want.

VBA Code:
Sub MultipleColumns()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim i As Long, j As Long, k As Long, n As Long
  
  Set sh1 = Sheets("h1")
  Set sh2 = Sheets("output")
  sh2.ResetAllPageBreaks
  
  n = 25    'rows per page
  k = 1
  j = 1
  For i = 1 To sh1.Range("A" & Rows.Count).End(3).Row Step n
    If j = 6 Then
      k = k + n
      j = 1
      sh2.HPageBreaks.Add Before:=sh2.Cells(k, j)
    End If
    sh2.Cells(k, j).Resize(n).Value = sh1.Range("A" & i).Resize(n).Value
    j = j + 1
  Next
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 0
Solution
Can you show us what your data looks like?

Hello @gir42. Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

Please try the following macro.

But before, create a sheet called "Output", in this sheet will be the result.
In the sheet "h1" put your data, rename in the macro "h1" and "output" by the names you want.

VBA Code:
Sub MultipleColumns()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim i As Long, j As Long, k As Long, n As Long
 
  Set sh1 = Sheets("h1")
  Set sh2 = Sheets("output")
  sh2.ResetAllPageBreaks
 
  n = 25    'rows per page
  k = 1
  j = 1
  For i = 1 To sh1.Range("A" & Rows.Count).End(3).Row Step n
    If j = 6 Then
      k = k + n
      j = 1
      sh2.HPageBreaks.Add Before:=sh2.Cells(k, j)
    End If
    sh2.Cells(k, j).Resize(n).Value = sh1.Range("A" & i).Resize(n).Value
    j = j + 1
  Next
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
Dante,
It worked perfectly! Thank you so much for taking time to help me!
 
Upvote 1

Forum statistics

Threads
1,215,641
Messages
6,125,980
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top