cln014,
Thanks for the new workbook.
Here is a macro solution for you to consider, that uses two arrays in memory, that will adjust to the varying number of raw data rows, and, columns.
Sample raw data, and, results, in the active worksheet (in two screenshots to fit in the MrExcel display area):
Excel 2007
| A | B | C | D | E | F | G | H | I | J |
---|
1 | CWID | Scholarship Code 1 | Scholarship Award 1 | Scholarship Award Amount 1 | Scholarship Code 2 | Scholarship Award 2 | Scholarship Award Amount 2 | Scholarship Code 3 | Scholarship Award 3 | Scholarship Award Amount 3 |
2 | 1 | 36116 | OS | 2500 | 17716 | BO | 21963 | 25810 | CC | 500 |
3 | 2 | 18116 | PR | 14700 | 17716 | BO | 21963 | 25810 | CC | 500 |
4 | 3 | 18116 | PR | 14700 | 17716 | BO | 21963 | 25810 | CC | 500 |
5 | 4 | 18116 | PR | 14700 | 17716 | BO | 21963 | | | |
6 | 5 | 7116 | SB | 4500 | | | | | | |
7 | 6 | 7116 | SB | 4500 | | | | | | |
8 | | | | | | | | | | |
9 | | | | | | | | | | |
10 | | | | | | | | | | |
11 | | | | | | | | | | |
12 | | | | | | | | | | |
13 | | | | | | | | | | |
14 | | | | | | | | | | |
15 | | | | | | | | | | |
<tbody>
</tbody>
externalawards002008_test
Excel 2007
| M | N | O | P |
---|
1 | CWID | Scholarship Code | Scholarship Award | Scholarship Award Amount |
2 | 1 | 36116 | OS | 2500 |
3 | 1 | 17716 | BO | 21963 |
4 | 1 | 25810 | CC | 500 |
5 | 2 | 18116 | PR | 14700 |
6 | 2 | 17716 | BO | 21963 |
7 | 2 | 25810 | CC | 500 |
8 | 3 | 18116 | PR | 14700 |
9 | 3 | 17716 | BO | 21963 |
10 | 3 | 25810 | CC | 500 |
11 | 4 | 18116 | PR | 14700 |
12 | 4 | 17716 | BO | 21963 |
13 | 5 | 7116 | SB | 4500 |
14 | 6 | 7116 | SB | 4500 |
15 | | | | |
<tbody>
</tbody>
externalawards002008_test
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
1. Copy the below code
2. Open your NEW workbook
3. Press the keys
ALT +
F11 to open the Visual Basic Editor
4. Press the keys
ALT +
I to activate the Insert menu
5. Press
M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys
ALT +
Q to exit the Editor, and return to Excel
8. To run the macro from Excel press
ALT +
F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
Code:
Sub ReorgData()
' hiker95, 04/30/2015, ME852326
Dim a As Variant, o As Variant
Dim lr As Long, lc As Long, luc As Long
Dim i As Long, j As Long, c As Long, n As Long
With ActiveSheet
lr = .Cells(Rows.Count, 1).End(xlUp).Row
lc = .Cells(1, 1).End(xlToRight).Column
luc = .Cells(1, Columns.Count).End(xlToLeft).Column
If luc > lc Then
.Columns(lc + 3).Resize(, 4).ClearContents
End If
a = .Range(.Cells(1, 1), .Cells(lr, lc))
ReDim o(1 To (UBound(a, 1) * ((lc - 1) / 3)), 1 To 4)
j = j + 1
o(j, 1) = "CWID": o(j, 2) = "Scholarship Code"
o(j, 3) = "Scholarship Award": o(j, 4) = "Scholarship Award Amount"
For i = 2 To UBound(a, 1)
For c = 2 To lc Step 3
If a(i, c) = "" And a(i, c + 1) = "" And a(i, c + 2) = "" Then
'do nothing
Else
j = j + 1
o(j, 1) = a(i, 1): o(j, 2) = a(i, c)
o(j, 3) = a(i, c + 1): o(j, 4) = a(i, c + 2)
End If
Next c
Next i
.Cells(1, lc + 3).Resize(UBound(o, 1), UBound(o, 2)) = o
.Columns(lc + 3).Resize(, 4).AutoFit
End With
End Sub
Before you use the macro with
Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension
.xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
Then run the
ReorgData macro.