Hello all,
I'd like to be able to create an invoice automatically using a workbook that has invoice blanks for each person and a data table with details of all people and invoices.
I've started the code to select the relevant worksheets and insert the specified number of rows based on the occurences of a person and date match.
What I can't work out is how to match the rows of data and populate the invoice lines. i.e if there are 3 occurence of name and date I can insert three rows into the relevant tab but don't know how to select the three rows of data from the source and populate the invoice.
I've pasted psuedo examples of what I am trying to achieve and the code I have so far if anyone can lend a hand.
Invoice tab:
Excel 2010
Appreciate any guidance, I know the code doesn't exactly relate to my example posted (it relates to my actual sheets), the example shows what I want to achieve.
Thanks
Paul
I'd like to be able to create an invoice automatically using a workbook that has invoice blanks for each person and a data table with details of all people and invoices.
I've started the code to select the relevant worksheets and insert the specified number of rows based on the occurences of a person and date match.
What I can't work out is how to match the rows of data and populate the invoice lines. i.e if there are 3 occurence of name and date I can insert three rows into the relevant tab but don't know how to select the three rows of data from the source and populate the invoice.
I've pasted psuedo examples of what I am trying to achieve and the code I have so far if anyone can lend a hand.
Invoice tab:
Excel Workbook | ||||
---|---|---|---|---|
A | B | |||
1 | Date | 14/02/2011 | ||
2 | Details | |||
3 | A | 100 | ||
4 | D | 130 | ||
Tom |
Excel Workbook | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Name | Date | Customer | Value | ||
2 | Tom | 14/02/2011 | A | 100 | ||
3 | **** | 13/02/2011 | B | 110 | ||
4 | Harry | 13/02/2011 | C | 120 | ||
5 | Tom | 14/02/2011 | D | 130 | ||
6 | **** | 14/02/2011 | E | 140 | ||
7 | Harry | 14/02/2011 | F | 150 | ||
8 | **** | 14/02/2011 | G | 160 | ||
Excel 2010
Details is a named range, in my code it is actually "Canx_and_retentions_Subtotal"
Data tab
Data |
Excel 2010
Code:
Option Explicit
Private Sub makeinvoice()
Dim i As Integer
Dim nRow As Integer
Dim wb As String
Dim ws As Worksheet
Dim iName As String
Dim iDate As String
Dim sText As String
Dim rng As Range
For Each ws In Worksheets
If Left(ws.Name, 3) = "Inv" Then
iName = Right(ws.Name, (Len(ws.Name) - 10))
iDate = Worksheets("Input").Range("B3")
nRow = Application.WorksheetFunction.CountIf(Worksheets("CRM Order Data").Range("AK:AK"), iName & iDate)
Range("Canx_and_retentions_Subtotal").Select
ActiveCell.Offset(2, 0).Resize(nRow).EntireRow.Insert
Else
End If
Next ws
End Sub
Appreciate any guidance, I know the code doesn't exactly relate to my example posted (it relates to my actual sheets), the example shows what I want to achieve.
Thanks
Paul