![]() |
|
#1
|
||||
|
||||
![]()
FWIW, an alternative approach would be to forget about using Word and doing the lot from within Excel. For example, the following macro creates all your labels on Sheet 2 of your existing workbook:
Code:
Sub Demo() Dim lRow As Long, lCol As Long Dim i As Long, j As Long, k As Long, l As Long, m As Long Dim WkShtSrc As Worksheet, WkShtTgt As Worksheet k = 0 Set WkShtSrc = ThisWorkbook.Worksheets("Sheet1") Set WkShtTgt = ThisWorkbook.Worksheets("Sheet2") With WkShtTgt .UsedRange.ClearContents .Columns("B:D").ColumnWidth = 43.3 .Columns("A").ColumnWidth = 10 .Columns("C").ColumnWidth = 10 .Rows.RowHeight = 240 With .Columns("A:D").Font .Name = "Arial" .Size = 12 End With End With With WkShtSrc lRow = .UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row lCol = .UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Column For i = 2 To lRow If .Cells(i, 1).Value = .Cells(i - 1, 1).Value Then With WkShtTgt.Cells(m, l) .Value = .Text & Chr(10) For j = 2 To lCol .Value = .Text & Chr(10) & WkShtSrc.Cells(i, j) Next End With Else l = (k Mod 2 + 1) * 2: k = k + 1: m = -Int(-k / 2) With WkShtTgt.Cells(m, l) .Value = "BOX " & WkShtSrc.Cells(i, 1) & Chr(10) For j = 2 To lCol .Value = .Text & Chr(10) & WkShtSrc.Cells(i, j) Next End With End If Next End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Mark J Rees | Mail Merge | 2 | 05-10-2013 06:00 PM |
![]() |
JohnFinNC | Mail Merge | 6 | 10-04-2012 06:36 PM |
![]() |
rohitjain80 | Mail Merge | 1 | 02-12-2012 03:42 AM |
Excel Multi Level Category labels | Spay | Excel | 0 | 03-14-2011 01:05 PM |
MailMerge Labels Question | trims30 | Mail Merge | 0 | 08-04-2010 05:21 PM |