Combining multiple columns of different lengths into one column

zachary217

New Member
Joined
Mar 16, 2014
Messages
2
Hi all,
This is my first time posting, so apologies if I don't articulate what I'm looking for perfectly. I have a set of data that gives people scores based on various metrics in a grid and would like to email people who receive a score greater than 0 in any of the categories. I've come to understand that I can use mailmerge and microsoft word to do this; however, I would like to write a macro to format the data I have in excel to be in a way that's easy to use the mailmerge function with, which is where I'm stuck. Here is a picture of a sample of the type of data I have, followed by how I currently have it organized based on a macro I've currently written, and then a sample of how I'd like it to look, which could be done by using either the data in the first or second examples, whichever is easier:

Original Data:

NameBasketballBaseballTennis
a321
b42
c11
d3
e4
f5
g26
h
i
j
k2
l
m1
n
o3

<tbody>
</tbody>


How I've sorted it in a separate worksheet using a macro:

BasketballLevelBaseballLevelTennisLevel
a3a2a1
c1b4b2
g2k2c1
m1d3
o3e4
f5
g6

<tbody>
</tbody>


This is how I'd like it to look (using either of the first two tables):

NameLevelSport
a3Basketball
c1Basketball
g2Basketball
a2Baseball
b4Baseball
k2Baseball
m1Baseball
o3Baseball
a1Tennis
b2Tennis
c1Tennis
d3Tennis
e4Tennis
f5Tennis
g6Tennis

<tbody>
</tbody>


Any suggestions/actual VBA code would be much appreciated. Thanks!
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You can get very close to that using the PivotTable wizard. Do Alt+D+P to start the wizard, and choose:
Multiple Consolidation Ranges/Next
I will create the Page Fields/Next
Select the original data/Add/Finish
( this will create a PivotTable )
In the actual PivotTable itself, double-click on the single figure that is the Grand Total for rows and columns
( this will drill-down and create a new sheet )
Sort and Filter the resulting list to however you want it.

That's it.
 
Upvote 0
I'm really impressed with the pivot table Glenn suggests. I'm going to play with that to improve my understanding of pivot tables. Possible code that will hopefully achieve the same :

Code:
Sub SortGrades()
Dim shSrc As Worksheet
Dim shDest As Worksheet

Set shSrc = Sheets("Sheet1")
Set shDest = Sheets("Sheet2")

shDest.UsedRange.ClearContents

DestRow = 1
For Sport = 1 To 3
    For i = 2 To shSrc.UsedRange.Rows.Count
        If shSrc.Cells(i, Sport + 1) <> "" Then
            With shDest
                .Cells(DestRow, 1) = shSrc.Cells(i, 1)
                .Cells(DestRow, 3) = shSrc.Cells(1, Sport + 1)
                .Cells(DestRow, 2) = shSrc.Cells(i, Sport + 1)
                DestRow = DestRow + 1
            End With
        End If
    Next
Next
End Sub
 
Upvote 0
Thanks Lexxie! That did exactly what I wanted!! The pivot table Glenn suggested also looks great, though for using it with mail merge I think it'd be easiest to use your macro that gets all the data on a single sheet. I appreciate the help and support and will try my best to dissect what the code is actually doing so I can understand it better and hopefully write up something myself next time I'm stuck like this!!


I'm really impressed with the pivot table Glenn suggests. I'm going to play with that to improve my understanding of pivot tables. Possible code that will hopefully achieve the same :

Code:
Sub SortGrades()
Dim shSrc As Worksheet
Dim shDest As Worksheet

Set shSrc = Sheets("Sheet1")
Set shDest = Sheets("Sheet2")

shDest.UsedRange.ClearContents

DestRow = 1
For Sport = 1 To 3
    For i = 2 To shSrc.UsedRange.Rows.Count
        If shSrc.Cells(i, Sport + 1) <> "" Then
            With shDest
                .Cells(DestRow, 1) = shSrc.Cells(i, 1)
                .Cells(DestRow, 3) = shSrc.Cells(1, Sport + 1)
                .Cells(DestRow, 2) = shSrc.Cells(i, Sport + 1)
                DestRow = DestRow + 1
            End With
        End If
    Next
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,790
Members
449,468
Latest member
AGreen17

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