Hi all
I am fairly new to this and struggling with a number of things but ultimately, I need to be able to find all rows with the same invoice number and then concatenate each invoice description cell into one cell at the end of my data table. So far I have the code below (which, I know, is not much at the moment) and this only identifies the first invoice number and copies the descriptions into separate cells in column J.
Additionally some of the description lines can be blank and for each invoice number there could be a variable number of rows.
I have tried a number of things to get it to loop through the whole of column D to do the same for each invoice number and to concatenate the invoice descriptions into one cell at the end of my data table (see table below) but am failing miserably. I would be grateful for any advice.
Sub FindInvoice()
Set wrk = Worksheets("Template")
Set inRng = Range("D1:D10000")
Set outRng = Range("J2")
' Starting point of data
findVal = Range("A2")
' Loop through rows in the input range / find result then copies
For cntr = 1 To inRng.Rows.Count
If inRng(cntr, 1) = findVal Then
outRng(outCntr + 1, 1) = inRng(cntr, 2)
outCntr = outCntr + 1
End If
Next cntr
End Sub
[TABLE="width: 1248"]
<TBODY>[TR]
[TD]Inv No Grouped</SPAN>[/TD]
[TD]Customer No.</SPAN>[/TD]
[TD]Customer Name</SPAN>[/TD]
[TD]Invoice No.</SPAN>[/TD]
[TD]Invoice Line Description</SPAN>[/TD]
[TD]Invoice Date</SPAN>[/TD]
[TD]Amount Outstanding</SPAN>[/TD]
[TD]Requested By</SPAN>[/TD]
[TD]Budget Holder[/TD]
[TD]Output column</SPAN>[/TD]
[/TR]
[TR]
[TD]102477</SPAN>[/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]FAO MRS T - EDUCATION DEPT SPECIAL NEEDS</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD] [/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]Reimbursement for cost of Speech & Language Therapy to Neil Jones</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]4 Hours SLT time in July 2005</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]3 Hours SLT time in Sept 2005</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]103220</SPAN>[/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]103220</SPAN>[/TD]
[TD] [/TD]
[TD="align: right"]16-Jan-2006</SPAN>[/TD]
[TD="align: right"]£1,608.82</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]103220</SPAN>[/TD]
[TD]Bill for 1/3rd of of the costs of Speech Therapists at the Outreach Service - 3nd quarter 2005/06 as attached</SPAN>[/TD]
[TD="align: right"]16-Jan-2006</SPAN>[/TD]
[TD="align: right"]£1,608.82</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]103220</SPAN>[/TD]
[TD]F.A.O. Mr D James - Torfaen Education Department</SPAN>[/TD]
[TD="align: right"]16-Jan-2006</SPAN>[/TD]
[TD="align: right"]£1,608.82</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]10484</SPAN>[/TD]
[TD]23211</SPAN>[/TD]
[TD]WELSH SCHOOL OF PHARMACY</SPAN>[/TD]
[TD]10484</SPAN>[/TD]
[TD]Refer to Credit Note SCRN/00000032 Newport LHB</SPAN>[/TD]
[TD="align: right"]26-Nov-2009</SPAN>[/TD]
[TD="align: right"]-£542.00</SPAN>[/TD]
[TD]ANDREW ASTON</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]23211</SPAN>[/TD]
[TD]WELSH SCHOOL OF PHARMACY</SPAN>[/TD]
[TD]10484</SPAN>[/TD]
[TD] [/TD]
[TD="align: right"]26-Nov-2009</SPAN>[/TD]
[TD="align: right"]-£542.00</SPAN>[/TD]
[TD]ANDREW ASTON</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP>[/TABLE]
I am fairly new to this and struggling with a number of things but ultimately, I need to be able to find all rows with the same invoice number and then concatenate each invoice description cell into one cell at the end of my data table. So far I have the code below (which, I know, is not much at the moment) and this only identifies the first invoice number and copies the descriptions into separate cells in column J.
Additionally some of the description lines can be blank and for each invoice number there could be a variable number of rows.
I have tried a number of things to get it to loop through the whole of column D to do the same for each invoice number and to concatenate the invoice descriptions into one cell at the end of my data table (see table below) but am failing miserably. I would be grateful for any advice.
Sub FindInvoice()
Set wrk = Worksheets("Template")
Set inRng = Range("D1:D10000")
Set outRng = Range("J2")
' Starting point of data
findVal = Range("A2")
' Loop through rows in the input range / find result then copies
For cntr = 1 To inRng.Rows.Count
If inRng(cntr, 1) = findVal Then
outRng(outCntr + 1, 1) = inRng(cntr, 2)
outCntr = outCntr + 1
End If
Next cntr
End Sub
[TABLE="width: 1248"]
<TBODY>[TR]
[TD]Inv No Grouped</SPAN>[/TD]
[TD]Customer No.</SPAN>[/TD]
[TD]Customer Name</SPAN>[/TD]
[TD]Invoice No.</SPAN>[/TD]
[TD]Invoice Line Description</SPAN>[/TD]
[TD]Invoice Date</SPAN>[/TD]
[TD]Amount Outstanding</SPAN>[/TD]
[TD]Requested By</SPAN>[/TD]
[TD]Budget Holder[/TD]
[TD]Output column</SPAN>[/TD]
[/TR]
[TR]
[TD]102477</SPAN>[/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]FAO MRS T - EDUCATION DEPT SPECIAL NEEDS</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD] [/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]Reimbursement for cost of Speech & Language Therapy to Neil Jones</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]4 Hours SLT time in July 2005</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]102477</SPAN>[/TD]
[TD]3 Hours SLT time in Sept 2005</SPAN>[/TD]
[TD="align: right"]19-Dec-2005</SPAN>[/TD]
[TD="align: right"]£94.52</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]103220</SPAN>[/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]103220</SPAN>[/TD]
[TD] [/TD]
[TD="align: right"]16-Jan-2006</SPAN>[/TD]
[TD="align: right"]£1,608.82</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD]ALISON STROUD</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]103220</SPAN>[/TD]
[TD]Bill for 1/3rd of of the costs of Speech Therapists at the Outreach Service - 3nd quarter 2005/06 as attached</SPAN>[/TD]
[TD="align: right"]16-Jan-2006</SPAN>[/TD]
[TD="align: right"]£1,608.82</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]20873</SPAN>[/TD]
[TD]TORFAEN COUNTY BOROUGH COUNCIL</SPAN>[/TD]
[TD]103220</SPAN>[/TD]
[TD]F.A.O. Mr D James - Torfaen Education Department</SPAN>[/TD]
[TD="align: right"]16-Jan-2006</SPAN>[/TD]
[TD="align: right"]£1,608.82</SPAN>[/TD]
[TD]GAIL ELIAS</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]10484</SPAN>[/TD]
[TD]23211</SPAN>[/TD]
[TD]WELSH SCHOOL OF PHARMACY</SPAN>[/TD]
[TD]10484</SPAN>[/TD]
[TD]Refer to Credit Note SCRN/00000032 Newport LHB</SPAN>[/TD]
[TD="align: right"]26-Nov-2009</SPAN>[/TD]
[TD="align: right"]-£542.00</SPAN>[/TD]
[TD]ANDREW ASTON</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]23211</SPAN>[/TD]
[TD]WELSH SCHOOL OF PHARMACY</SPAN>[/TD]
[TD]10484</SPAN>[/TD]
[TD] [/TD]
[TD="align: right"]26-Nov-2009</SPAN>[/TD]
[TD="align: right"]-£542.00</SPAN>[/TD]
[TD]ANDREW ASTON</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP>[/TABLE]