Create invoice automatcally

towners

Board Regular
Joined
Mar 12, 2009
Messages
225
Office Version
  1. 365
Platform
  1. Windows
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 Workbook
AB
1Date14/02/2011
2Details
3A100
4D130
Tom
Excel Workbook
ABCD
1NameDateCustomerValue
2Tom14/02/2011A100
3****13/02/2011B110
4Harry13/02/2011C120
5Tom14/02/2011D130
6****14/02/2011E140
7Harry14/02/2011F150
8****14/02/2011G160
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
 
That's it.

Many thanks Andrew, appreciate your help.

Paul
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,215,442
Messages
6,124,886
Members
449,194
Latest member
ronnyf85

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top