dirock,
Detach/open workbook Consolidate_acct_no - Sum Join - dirock - EF854189 - SDG15.xlsm and run the Consolidate_acct_no macro.
If you want to use the macro on another workbook:
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, by highlighting the code and pressing the keys CTRL + C
2. Open your 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 by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
Option Explicit
Sub Consolidate_acct_no()
' stanleydgromjr, 08/21/2012
' http://www.excelforum.com/excel-programming-vba-macros/854189-vba-loop-through-table-combine-like-columns-and-add-and-concatenate-respective-cell.html
Dim r As Long, lr As Long, n As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, 1).End(xlUp).Row
Range("A3:I" & lr).Sort key1:=Range("A3"), order1:=1
For r = 3 To lr
n = Application.CountIf(Columns(1), Cells(r, 1).Value)
If n > 1 Then
Cells(r, 7).Value = Application.Sum(Range(Cells(r, 7), Cells(r + n - 1, 7)))
Cells(r, 9).Value = Join(Application.Transpose(Range(Cells(r, 9), Cells(r + n - 1, 9))), ", ")
Rows(r + 1).Resize(n - 1).Delete
lr = Cells(Rows.Count, 1).End(xlUp).Row
End If
Next r
Application.ScreenUpdating = True
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
Then run the Consolidate_acct_no macro.
Bookmarks