Okay. The principle is the same but because of the size of your data table it is perhaps easier to use a seperate sheet to get the desired result.
In this workbook, I have called the Sheets "Data" & "Result", once the setup is complete these sheet names can be changed and the various formulae will automatically update.
1/. Create the dynamic named ranges. (Formulas > Name Manager)
"DataTable"
Refers to:
Syntax
OFFSET(reference,rows,cols,height,width)
reference:= Data!$A$2 (This is the top left cell of the table, therefore the next two values are zero, i.e. no offset)
rows:= 0
cols:= 0
height:= COUNTA(Data!$AH:$AH)-1 (This is the number of rows the table will have, the -1 removes the header from the count)
width:= COLUMN(Data!AQ$1) (this returns the last column number in the table, in this case 41)
Data!$AH:$AH is the column that is most likely to have continuous data that defines the height of the table. This is then used to control the height of the other named ranges.
e.g.
"Amount"
Refers to:
For more on named ranges see this link Contextures - Excel Names -- Excel Named Ranges
and for more techniques see Chip Pearson - Defined Names
2/. With Sheet "Data" in the "Helper Column" (Column AQ) concatinate "Amount by Line Item" & "Shipment Id"
In AQ2
Drag/Fill Down to the last row in your table.
In AR2 "Remove Duplicates"
Drag/Fill down until a blank is returned.
This will remove the duplicate strings.
This only works for Text values. Numbers and mixed data require different formulae, but as we have concatinated the helper column then the results are text strings.
3/. With Sheet "Result"
Either paste the headers, or in A1
Drag/Fill Right to Column AO (i.e. - the last Column in Sheet "Data")
In A2 this array formula, given you are using 2007
Confirm with Ctrl+Shift+Enter not just Enter.
Drag this down until a blank cell is returned, then Right to Column AO.
Zeros are returned for empty and zero cells with the sample you have provided, these can be suppressed with Number Formatting where appropriate.
I have formatted the first three columns of Sheet "Result" to demonstrate the result
Select the appropriate columns then
Home > Format Cells... Number > Custom
Type:
4/. Finally copy Sheet "Result" and Paste > Paste Special > Values to a suitable destination if required.
All this can of course be done with a macro, but you will, in my opinion, learn more by understanding native formula, rather than using VBa.
Changes are easier with this template using native methods, it can often be an endless task using VBa.
To use Paste your new data into Sheet "Data" and drag the formulae to suit.
Sorry about the rant, but it should stand you in good stead if you can follow and understand the steps.
[EDIT]
With 10,000 rows it will take some time to calculate, but so probably will a VBa solution.
For a task that only has to be done once a week is this really a problem?
Once the formulae have been expanded to cover your typical table size and retained as a template, it should just be a matter of pasting and having a coffee ...
...
Bookmarks