How to generate invoice numbers with a combination of customer codes without duplicates and sequentially with VBA - excel

Dear All Master,
How to generate invoice numbers with a combination of customer codes without duplicates and sequentially with VBA.
so the position in "C2" is the customer code.
So the "serial" will change continuously in order with the customer code. Does it need invoice numbers stored in their own sheets so that they make it easier for duplicates and sequential to occur? if necessary how?. Please recommend the best solution
in "C4" is the combination invoice number.
JS : COMPANY NAME
12 : MONTH
22 : 2 DIGIT YEAR
XX : CUSTOMER CODE
001 : SERIAL
EXAMPLE
JS-12-22-10-001
JS-12-22-10-002
JS-12-22-11-001
JS-12-22-11-002
Sub generatenumberinvoice()
Sheet1.Range("c3").Value = Sheet1.Range("c3").Value + 1
End Sub

This is not directly help you, but maybe you can have a look and modify it according to your case.
Make a new workbook
Rename Sheet1 into TABLE, Sheet2 into DATA, Sheet3 into FormInput
Type on each sheet exactly like in the picture below. For the time being, ignore the INPUT button which seen in the image of sheet FormInput
In the Name Manager, create a named range CustID which refers to:=OFFSET(TABLE!$A$1,0,0,COUNTA(TABLE!$A:$A),2)
Create another named range : data which refers to: =OFFSET(DATA!$A$1,0,0,COUNTA(DATA!$A:$A),4)
Create another named range : trans which refers to : =OFFSET(FormInput!$A$6,0,0,COUNTA(FormInput!$A:$A)-4,1)
Finally, copy the formula below and paste it to cell B3 of sheet FormInput =IF(COUNTIF(INDEX(data,,3),"*JS-"&TEXT($B$1,"yy-mm-")&VLOOKUP($B$2,CustID,2,FALSE)&"*")<>0,"JS-"&TEXT($B$1,"yy-mm-")&VLOOKUP($B$2,CustID,2,FALSE)&"-"&TEXT(AGGREGATE(14,6,RIGHT(INDEX(data,,3),3)/(LEFT(INDEX(data,,3),12)="JS-"&TEXT($B$1,"yy-mm-")&VLOOKUP($B$2,CustID,2,FALSE)&"-"),1)+1,"000"),"JS-"&TEXT($B$1,"yy-mm-")&VLOOKUP($B$2,CustID,2,FALSE)&"-001")
Try to type aaa (the name of customer) in cell B2 sheet FormInput. If everything above done correctly, cell B3 will show JS-22-12-10-001. Type bbb then it show JS-22-12-11-001, type ccc then it show JS-22-12-12-001. The last 3 characters always show 001 (which means this is the first invoice number of Dec-22 for whatever id), because there is no data in sheet DATA. Hence it just show 22-12 depends on the date seen in cell B1, and -10 or -11 or -12 depends on the name of the customer seen in cell B2.
Try to change the date to something like 21-nov-22. Cell B3 will show 22-11 and the CustID depends on the name seen in cell B2, and the number always show "001". Play around by changing the date of different month and change the name (aaa or bbb or ccc) so you understand thoroughly how it works.
Now, fill data in sheets DATA exactly like the image below
Back in FormInput, fill the date with Nov-22 month and fill the cust name with aaa, cell B3 will show the next invoice number: JS-22-11-10-006 because the formula read the data that the last number for id 10 in Nov-22 is JS-22-11-10-005, so the formula add 1 to the serial number in cell B3 for id 10 (customer aaa in this case).
Still in November date, type bbb for cust name. It will show JS-22-11-11-001 in cell B3 because there is no data for id 11 of Nov-22. So this is the first invoice number of Nov-22 for id 11 (customer bbb in this case).
Now change the date to December date, then type aaa for cust name. Cell B3 will show the next invoice number for id 10 in Dec-22 is JS-22-12-10-002, because the formula see that the last number in the data for id 10 of Dec-22 is "001".
Still in December date,
type ccc for cust name. Cell B3 will show JS-22-12-12-004.
type bbb for cust name. Cell B3 will show JS-22-12-11-001 which means this is the first invoice number for id 11 in Dec-22.
Play around by filling a different invoice number in sheet DATA then fill the date and the name of the cust in sheet InputForm.
The INPUT button seen in InputForm is a vba code to input the data seen in InputForm into sheet DATA. But this is another case, and if you want to know it, I think you'd better open another question.
Thank you.
Thanks to Mr. Peter_SSs, because I get the formula for cell B3 from him in this link

Related

I need to retrieve the date from the row that will deplete my inventory

This is hard to explain...
I have a report that I pull from our MRP system that gives me a Due-Date, a quantity required, and an item number. There will usually be several rows with the same item number each representing a different sales order.
I have another report that gives me the on hand quantity for each item. In this report, each item is listed only once.
I need to get the Due-Date that corresponds to the row that will use up the last of my inventory. (Inv. runout)
Due-Date
QTY-REQ
ITEM
4/27/21
5
C
4/28/21
7
A
4/29/21
5
B
4/30/21
1
B
5/1/21
13
A
5/2/21
4
A
5/3/21
12
C
5/4/21
1
A
OHQ
ITEM
INV. RUNOUT
10
A
formula here, Result should be 5/1/21
5
B
result should be 4/30/21
10
C
result should be 5/3/21
I hope this makes sense, if not, please let me know what I can answer to help with this.
-Nick
You'll need a new column on the first report using IF(SUMIFS( to only show the date of lines where the stock runs out at or before that date. Then in the second report, use MINIFS(), a fairly new function, to find the earliest date in that column that matches each product.
In the below example I'm assuming that both of the above reports shown are columns A B and C, in the same excel file, on sheets called Report1 and Report2.
In cell Z2 on Report1, enter the formula IF(SUMIFS(B:B, A:A, "<=" & A2, C:C, C2) > INDEX(Report2!A:A,MATCH(Report1!C2,Report2!B:B,0)), A2, "") and copy down for all rows. This will only display the date where the stock has run out by that date.
In cell C2 on Report2, enter the formula =MINIFS(Report1!Z:Z, Report1!C:C, Report2!B2) to get the earliest relevant date displayed from the formula above.

Determining NETWORKDAYS based on Multiple Criteria

Summary
Sheet 1 - Includes PTO data for every person on a team. This sheet gives me the person's name, the start and end date of their PTO for the year.
Ex:
Sheet1
--------Col1----------------Col2----------------Col3
Row1 John 06/01/2017 06/10/17
Row2 John 06/25/2017 07/05/17
Row3 Jane 06/25/2017 07/05/17
Row2 Robb 06/11/2017 06/15/17
Sheet 2 - Is projecting PTO per Resource Per Month. The Sheet includes a Cell that has the Start Date of the Projection Report and the End Date of the Projection Report. It also includes every team member on the sheet. So think...
Sheet2
A1 = "06/01/2017"
A2 = "06/31/2017"
A5 = "Name of Person"
A6 = "John"
A7 = "Jane"
A8 = "Robb"
B5 = "# of PTO Days for Reporting Period"
On this sheet, Column 2 (B6:B8) I am trying to grab the total network days of each person's PTO based on the date range between A1 and A2. So, those taking PTO that spills into the next month, I wouldn't want to grab TOTAL Network Days for that person, I'd only want to grab Network Days that fall into the range of A1 and A2.
Example - John has two PTO ranges. One whose range is 06/01 - 06/10 (which falls into the range of A1 and A2), but another whose range is 6/25 - 7/05 (so, the 7/1 - 7/5 does NOT fall in the range of A1 and A2). The later, I'd only want to record the NETWORKDAYS within June.
I've tried a few different formulas that enables me to read the name of the employee and only pull network days that fall in the range of A1 and A2, but I'm having difficulty find something that works.
Anyone know how I could have B6:B8 give me the data related to the Resource Name and try to grab all appropriate networkdays for June in Sheet1?
Thanks!
You would need one helper column to extract the networkdays,
Column D is your helper column which finds the networkdays based on the range provided in Sheet2. Use the below formula in column D (sheet1) and drag down,
=IF(AND(B1>=Sheet2!$A$1,C1<=Sheet2!$A$2),NETWORKDAYS(B1,C1),IF(AND(B1<Sheet2!$A$1,C1<=Sheet2!$A$2,C1>=Sheet2!$A$1),NETWORKDAYS(Sheet2!$A$1,C1),IF(AND(B1>=Sheet2!$A$1,B1<=Sheet2!$A$2,C1>Sheet2!$A$2),NETWORKDAYS(B1,Sheet2!$A$2),0)))
Now you will have networkdays for each entry in sheet1, need to use a SUMIF to total it for each person in sheet2. Use the formula in Sheet2 B6 and drag down,
=SUMIF(Sheet1!A:A,A6,Sheet1!D:D)
Hope this helps.
Note:- NETWORKDAYS ignores the weekends.

Excel: Index match if date matches month?

I have two excel sheets:
Data:
Column A Column E
01/01/2017 Supplier 1
05/01/2017 Supplier 2
05/01/2017 Supplier 1
Sheet 2:
I am trying to look up the supplier where the month of the date in column A matches the month number in cell F11.
F11 = 1
=IF(ISERROR(INDEX(Data!$A:$I,SMALL(IF(MONTH(Data!A:A)=$F$11,ROW(Data!$A:$A)),ROW(1:1)),5)),"",INDEX(Data!$A:$I,SMALL(IF(MONTH(Data!A:A)=$F$11,ROW(Data!$A:$A)),ROW(1:1)),5))
For some reason this doesn't work and i get no result.
I also need to only list each supplier name the once, unique values. But i believe my formula gives me the same result twice.
Please can someone show me where i am going wrong?
Can't you do this with a pivot table?
Just drag the date field into the columns box, then right-click, choose 'Group' and choose 'months'. Then drag the supplier field underneath it and you should get a list of all unique suppliers by month.
Edit:
Example below.

Formula to Get data for a specific date

Date Time Country Desc
16/04/14 8.30 am India abcd
16/04/14 9.30 am India pqrs
17/04/14 9.30 am India xyz
17/04/14 10.30 am India abcd
I wish to get all the data of 16/04/14 in another sheet using formula. Vlookup takes only the first row data as reference is 16/04/14. Is there any other way to get data.
Try this then:
Assuming you have this data in Sheet1:
And you want to get all matches of dates in Sheet2 like this:
What you need to do is use this formula:
=IFERROR(INDEX(Sheet1!A$1:A$5,SMALL((IF(Sheet1!$A$1:$A$5=$E$1,ROW(Sheet1!A$1:A$5))),ROW($A1)),1),"")
Above is an Array Formula entered by pressing Ctrl+Shift+Enter.
Enter it in A2 then copy on the remaining cells.
For our example, I copied it until Row 10 (A2:D10).
Then you just need to type in the value you want displayed in E1 as shown in the picture.
Then all the columns will populate with the data that you need.
Hope this helps.
Important: The ranges in the formula needs to be adjusted to suit your needs.

Transfer data from one worksheet to the next based on cell values

I had trouble titling this, and I think it is better explained with examples. I am not an extremely experienced excel user, but was asked to figure this out.
Worksheet 1 (delivered by software) is formatted like this:
12/17/2013
Hour Delivered
00.00-00.59
Employee 1 18
Employee 2 17
Total For Hour 35
01.00-01.59
Employee 1 18
Employee 2 17
Employee 3 12
Total For Hour 47
... etc until hours 24.00-24.59
The number of employees in the group per hour is different each day, so i don't think that I can just simply reference the cells.
The worksheets that I want to transfer the data from worksheet 1 to are based on date, so there is one for each day. (12/17 worksheet, 12/18 worksheet, etc...)
And this is the format of the date worksheets:
Employee 00.00-00.59 | 01.00-01.59 | etc. until hours 24.00-24.59
Employee 1 18 18
Employee 2 17 17
Employee 3 12
Employee 4
Employee 5
So basically I need the data from worksheet 1 transferred over to the individual date worksheets. I believe, the amount of employees being different for each hour/day makes this difficult. Does anyone here have any ideas of how this can be accomplished?
Also, if there are any questions, please let me know.
This should be possible without any VB in two steps. First step is to add further columns to Worksheet 1 that normalise the data. Second step is to create a pivot table using that normalised data.
By "normalise" I mean add columns in Worksheet 1 for Date, Hour, Employee and Delivered using formulae that copy values from your existing columns A and B. Let me know if you need more help with that.
Edit: adding details ...
Suppose Worksheet 1 has the values you indicated in column A and B, and that you want Hour in column D. Suppose row 1 just contains column headings. Leave row 2 totally empty. The formula in col D needs to say "If the value in col A looks like an hour, then copy it, otherwise repeat the hour from the line above." A simple way to determine if a row in Worksheet 1 is an Hour is to look for a decimal point in position 3. So put =IF(MID(A3,3,1)=".",A3,D2) in cell D3 and copy that formula down.
I'm sure you can construct a similar formula for the Date, Employee and Delivered columns.
Maybe add a condition to the formulae to say "If the value in col A starts with 'Total' then leave the cell empty".
If there aren't a lot of data and the setup is exactly how you've displayed them above, a simple formula can solve this.
Assuming that my raw export is in sheet Base, cell A1 and my intended output starts in sheet Output, cell A1, you can use this formula on cell B2:
=IF(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0)=$A2,OFFSET(INDEX(Base!$A:$A,MATCH(B$1,Base!$A:$A,0)+ROW(1:1),0),0,1),0)
The premise is simple. It locates the correct hour using INDEX + MATCH, then OFFSETs it by the correct number of ROWs. This is assuming, of course, that your employees are in the same location under every hour (ie Employee 1 is always one (1) row below the hour, Employee 2 is always two (2) rows below, etc). We also add a check if the employee name matches so that it will return 0 if the employee is not there.
Here are some screencaps:
Sample data:
Output:
Of course, this is just the basic premise. If you have multiple dates in a sheet, it's just a matter of manipulating this formula further. Off the top of my head, locating the correct date and adding the correct offset can also work.
Let us know if this helps or if a VBA or the Pivot option seems best.

Resources