Can't get a number in the correct cell

Important Notice


Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.

  • I have a table with multi columns.

    I use a code to transfer all the data from a listbox to an Excel sheet.

    The listbox contains an order from 1 client at the time, with different articles the client ordered.

    Everything is wroking fine except for the order number. If someone orders 4 articles, the code transfers the 4 lines perfectly but puts the order number in the last row and leaves the cells above blank. I would like that the code puts the order number in the first row of the order an leaves the cells below blank.

    This is the code I'm using:

    When I put the code line (with Range (M2) before "Next r", the code puts the order umber behind every line of the order, that is not what I want. The order should only get one order number.

    It doesn't matter where I put the line for the order number, it is always wrong. Could somebody help me please?

    Thanks in advance.

    • Best Answer

    Maybe try this:


  • In that case, maybe need to change


    From:

    Code
    ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(1, 8) = Sheets("Bestelde Artikelen").Range("M2").Value + 1

    To:

    Code
    ThisWorkbook.Sheets("Bestelde Artikelen").Range("A" & Rows.Count).End(xlUp).Offset(2, 8) = Sheets("Bestelde Artikelen").Range("M2").Value + 1
  • You were right the first time. I thought you just replaced the line but you also changed the row to (1, 8).

    I didn't noticed. I'm sorry. When I tried before, it was with (0, 8 ) and that didn't work of course.

    But now it works just fine with (1, 8).

    Thanks

  • I still have an issue.

    I would like that the order number appears on every line from the same order.

    Now it puts the order number on the first line only (what I asked initially but I see now that this is wrong).
    When I put the code line into the loop, It creates for every line a new increased number.
    If the order contains 4 order lines, the order number should be the same for the those 4 lines.

    Could some one help me?

    Thx in advance.

  • Maybe try this instead:


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!