Mailmerge data layout - vertical or horizontal

JugglerJAF

Active Member
Joined
Feb 17, 2002
Messages
264
(Apologies of this needs to be in a Word forum, but it is 50% Excel related!)

I have some data that I use to create a mailmerge, and in its raw form, the data looks like this:
hardwaresupportprice
Alphaa1£11
Alphaa2£12
Bravob1£22
Bravob2£24
Bravob3£26
Charliec1£33

<tbody>
</tbody>

From this, I need a mailmerge to produce 3 letters (one each addressed to Alpha, Bravo, and Charlie) and each letter needs to show the support description and price for all available products, so the final output would be:
1 letter to Alpha, listing two levels of support (a1 and a2), and their associated prices (£11 and £12)
1 letter to Bravo, listing three levels of support (b1, b2, and b3), and their associated prices (£12, £22, and £24)
1 letter to Charlie, listing one level of support (c1), and its associated price (£33)

The current process for doing this requires the layout of the data file to be changed from the tabular "vertical" format above (6 rows, 3 columns) to a "horizontal" format (3 rows, six columns) as shown below.
hardwaresupport_1price_1support_2price_2support_3price_3
Alphaa1£11a2£12
Bravob1£22b2£24b3£26
Charliec1£33

<tbody>
</tbody>

Is there any way of doing the mailmerge with the data in the original layout so that I don't have to amend the layout every time?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,545
Office Version
365
Platform
Windows
How about using this to change the format
Rich (BB code):
Sub JugglerJAF()
   Dim Cl As Range
   
   With CreateObject("Scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.count).End(xlUp))
         .Item(Cl.Value) = .Item(Cl.Value) & Cl.Offset(, 1).Value & "|" & Cl.Offset(, 2).Value & "|"
      Next Cl
      Range("F2").Resize(.count, 2).Value = Application.Transpose(Array(.Keys, .Items))
      Range("G2:G100000").TextToColumns Range("G2"), xlDelimited, , , False, False, False, False, True, "|"
   End With
End Sub
 

JugglerJAF

Active Member
Joined
Feb 17, 2002
Messages
264
Thanks for the suggestion. I do already have a macro that converts the data, but it's not as elegant as your solution.

I'll have a look and see if I can use this shorter approach in the future.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,545
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,078,466
Messages
5,340,484
Members
399,378
Latest member
voodoo1

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top