Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 27

Thread: Automatic numbering up, with two matches

  1. #1
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location

    Automatic numbering up, with two matches

    Hello, everyone.
    I ask for your assistance for my problem, which I can not find a solution to.
    I'll also attach a file.
    I can not find a solution how can I automatically assign a number to a subsequent sale.
    My table is from A2: E - by the end.
    In column b2 - down I have the number of documents
    in column C - I have sales dates
    in column D - I have things sold
    in column E - the object in which the goods are sold
    I do not know how each item and every item sold can be automatically numbered (suppose with a macro) every subsequent sale, and if we have the same documents from a particular object but with different goods sold, the numbering to be the same.
    I scoured the whole internet, but I could not find such a solution anywhere. Please for some help on your part, with infinite gratitude.
    Attached Files Attached Files

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    According to your Business Rules, the Numbers in A14 to A22 are wrong.

    Also
    if we have the same documents from a particular object but with different goods sold, the numbering to be the same.
    Unless it is possible for different Shops (Objects) to order on the same document, that can be stated as:
    Each Document Number must have it's own Sequential Sales number in column A

    When sorting the tables by date or by document number, the Document numbers are sequential and give the same result you want in column A, just with different numerical values.

    A
    Doc #
    1 7420
    1 7420
    2 7424
    3 7425
    3 7425
    4 7426
    5 7429
    5 7429
    6 7430

    That is a simple formula in A3, (A2 must be entered by hand.)
    A3.Formula= "=If(B3=B2,A2,A2+1)" and copy down to the end
    Last edited by SamT; 12-17-2017 at 08:49 AM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Hi SamT,
    from A14:A22 I have shown what should be the result, otherwise the table starts from A2 until the rows are completed.
    If you let me explain, I have found this formula, but it counts only on column B2:B.
    I have two criteria: The first is - Objects (column E2:E), the second is the invoices that are in column B2:B.
    The idea is the following: I first check the Objects (E2:E), then the invoices (B2:B).
    Every first invoice comes from a particular Object - it should start with 1 if there are 2,3,4 Invoices with the same number then the result should be again = 1 if it is not increased and the next invoice becomes the number 2 ect..... This applies to everyone - the Object and the incoming invoices.

    Thank you in advance.
    Maybe a macro is done, the question is to do, what I can not do.

    I will attach the search result again from A2 to the end......
    next number
    Invoices
    date
    sales
    Objects
    1
    7420
    3.12.2017 sales 3
    1
    7420
    3.12.2017 sales1 3
    1
    7424
    4.12.2017 sales2 2
    1
    7425
    5.12.2017 sales3 1
    1
    7425
    5.12.2017 sales4 1
    2
    7426
    5.12.2017 sales5 2
    2
    7429
    6.12.2017 sales6 1
    2
    7429
    6.12.2017 sales7 1
    3
    7430
    7.12.2017 sales8 1
    from A2 to the end

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    The rules behind this example need further clarification

    1. How can the same invoice be entered by two different sales descriptive (Sales, Sales1),(Sales3,Sales4), (Sales6,Sales7), for example? BTW the logic in the numbering in the Sales column is incorrect.

    2. What rule is applied to determine the increase in number in the next number column given that invoices # 7425 (2 of) and 7426?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Hello Aussiebear,
    column D2: D is not important, there may be a mirror, apples, nails what you think.
    The formula found by me and the one proposed by SamT is as I want, but the sequence is only by criteria invoices. The formula works, but can not distinguish that invoices come from different Objects.
    The problem with me, which I can not solve, is that I have two criteria: The first is - Objects, the 2nd is - the invoices.
    I remain available if you have more questions.
    Now: first invoices from second Object is 7424 = 1, second invoices is 7426 = 2
    first invoices from first Object is 7425 = 1 and we have two times (1,1), second invoices is 7429 = 2 (2,2), ect...

    Thanks in advance.

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    The idea is the following: I first check the Objects (E2:E), then the invoices (B2:B).
    Every first invoice comes from a particular Object - it should start with 1 if there are 2,3,4 Invoices with the same number then the result should be again = 1 if it is not increased and the next invoice becomes the number 2 ect..... This applies to everyone - the Object and the incoming invoices.
    That's not what your table(s) show.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    SamT,
    that is exactly how I described it.
    please explain to me what is wrong.

    I have found this formula too, but I do not know how to get the second criteria for Objects and get it into this formula?
    Attached Images Attached Images
    Last edited by k0st4din; 12-17-2017 at 01:54 PM.

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Different Objects, Different Invoices, Same Number
    next number Invoices Objects
    1
    7420
    3
    1 7420 3
    1 7424
    2
    1 7425
    1
    1 7425 1

    You said different Objects OR different Invoices = New Number

    Is it Ok for Different Objects to use the same Invoice Number?
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    in A3 try the following IF(AND(E3=E2,B3=B2),A2+1,A2)
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Quote Originally Posted by SamT View Post
    Different Objects, Different Invoices, Same Number
    next number Invoices Objects
    1
    7420
    3
    1 7420 3
    1 7424
    2
    1 7425
    1
    1 7425 1

    You said different Objects OR different Invoices = New Number

    Is it Ok for Different Objects to use the same Invoice Number?
    That is, for each Object to number from number 1 to the last number, and as in your and my example if we have the same invoices to have the same numbers

    Quote Originally Posted by Aussiebear View Post
    in A3 try the following IF(AND(E3=E2,B3=B2),A2+1,A2)
    The formula does not work as I want
    2017-12-17_234913.jpg

  11. #11
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    For each Shop, (AKA Object,) number each unique Invoice from 1 to n in column A. At the next Shop, start numbers over at 1
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  12. #12
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    I do not know SamT,
    it's a big circus,
    just comes an invoice and I look at which Object is, and it's the first number because the next one from the same object will be the second. This is the case for all Objects.
    If there was a range I would find a way to do it, but here the first come to a particular Object - is number 1.
    The most stupid thing is that the server numbers are running sequentially, and who first writes an invoice for this site is the number one, but at the same time, the next site that issued an invoice for it is the first one. Then I start looking for the second invoice for an object and it becomes number two and so on.
    Something comes to mind with a macro - by first sorting by object, then by invoice, so the first number will be number one, then number two and so on. After a few rows, we'll see the second object, and the first invoice arrived to be number one, two, and so on. Keeping the rule, if there are several sales on the same invoice, the number will remain the same.
    Last edited by k0st4din; 12-17-2017 at 09:57 PM.

  13. #13
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Presorting is the most efficient way. I think this will need a Macro.

    Something like
    A1 = 1
    For i = 3 to lastrow
    IF Cells i, E = Cells i-1, E then
    If cells i, B = cells i-1,  B THen 
    Cells i, A = Cells i-1, A + 1
    Else
    Cells i, A = 1
    End If
    End if
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  14. #14
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Hi SamT,
    if I do not do anything, it gives me a mistake.
    Could you have a look?
    Thank you
    Attached Images Attached Images

  15. #15
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    That's not VBA code. Fix it.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  16. #16
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    The problem is I do not know how!
    Would you please help me, please?

  17. #17
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Place this code in a standard module and run it from the Tools >> Macros Menu on your worksheet

    Public Sub SamT()
    Dim i as long
    Dim LastRow As Long
    
    With ActiveSheet
    .Range("A1") = 1
    LastRow = .Cells(Rows.Count, "E").End(xlUp).Row
    For i = 3 to lastrow
    If .Cells(i, "E") = .Cells(i-1, "E") And .Cells(i, "B") = .Cells(i-1, "B" Then
    .Cells(i, "A") = .Cells(i-1, "A" + 1
    Else
    .Cells(i, "A") = 1
    End if 
    End With
    End Sub
    Please, Kost4din, study this code and my previous pseudocode and LEARN how to write very basic VBA. VBA is Basic English, It's not like C# where you have to memorize a bunch of cryptic code symbols.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  18. #18
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Hi again SamT,
    you know how many times I've tried to teach it this macro writing, but it has always been very difficult for me. And I'm not one of those who do not want to read.
    Here is also in this macro, there is some error and I can not fix it.
    On this End With tells me without "with" - I removed it and again gave me a mistake, then another one told me it was wrong, it was not blocked, it was blocked.
    I tried to change it in several ways and always ended in failure
    Only with "end", Next, double End if, End if
    2017-12-19_070003.jpg

  19. #19
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I'm sorry, my bad. I was not using the VBA editor to write that code.

    Insert the line
    Next i
    Before the line
     End with
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  20. #20
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    237
    Location
    Hi SamT,
    I am totally desperate.
    I put this line on, I pressed the button and the finish was one thing, there was not even a stack on either E or B, and the number sequence everywhere put number 1.
    A big dilemma is my problem.
    I do not know what to do if someone comes to mind, let's share it.
    I am grateful to everyone.
    Greetings SamT
    2017-12-19_205207.jpg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •