Cutting Stock Lengths

Here’s a program I wrote some time ago to determine how much stock (such as lumber) of a particular length you would need to get a certain number of cut stock. It sorts the cuts from longest to shortest and uses up the stock in that order. That may not be the most efficient use of stock, but I can’t think of a better way.

excel range and message box showing cut stock

I should really put the output on a sheet instead of a message box so it could be printed. I started to do something similar for square feet instead of linear feet (like plywood instead of 2×4s), but it was way too hard. You can download

28 thoughts on “Cutting Stock Lengths

  1. Dick, this could be very useful, but what about the amount of wood you lose with each cut? Needs to have a place to put how wide the saw blade is to account for this in each cut you make on a board. As you said it would be better to have the results put on a sheet and maybe even the “waste” that is left in each board, just a thought

  2. The width of a saw blade? What are you making, Scandinavian furniture? It might be good to have a generic waste factor in there. The user could enter either a percentage or a hard measurement and that could be added to each cut, or rather subtracted from the remaining stock after each cut.
    I thought about tracking the waste, but never got around to doing it.

  3. No am not making Scandinavian furniture but with a 1/8? saw blade and if you have 36? stock and want three 12? boards you would end up with two 12? and one 11 3/4?. If you are making anything, except maybe “rough” framing a house that is a big deal. And of course the longer the stock and the more cuts you make or a wider saw blade, this becomes more of a problem.

  4. Back in my University days our Operational Research Mathematics class (Dr Lynn was our lecturer if I remember correctly) was set the task of using linear programming and/or trim loss theory to work out how to minimise waste for a carpet manufacturer.

    Obviously they sold rolls of carpet in various lengths and widths but cut from one roll.

    I did come up with a neat solution in Algol but have never had the need to use it again (or translate it into any other language).

    Professor George B. Dantzig invented the the “simplex method” and “linear programming” whilst at Stanford, so if you need more information look it up on the web!

    Alternatively, email me and I might be able to find the Algol program!!!

  5. Hi Simon. I would be interested in your Algol solution. I happen to like OR when I was in school and am curious to see your solution. I hope you can find it and share it. Thanks for your time.


  6. Hello, first time here. Dick Kusleika – I work in the steel fabrication industry and could use your stock cutting VBA to some degree. What I would like to know is would it take much to have it tell me which pieces of which length to cut from each stock length. i.e., 2 pieces 18′ 6? long to cut from a 40′ 0? stock length piece. I would be dealing with hundreds of pieces of varying lengths from 1′ 0? to 58′ 0? being cut from 20′ 0?, 40′ 0? and 60′ 0? (various quantities of each) stock lengths as well as several random stock lengths left over from previous jobs.

    Thank you, Ed

  7. Hello, first time here. Dick Kusleika – I work in framing industry and am very happy to find your cutting stock length program. Would you consider adding a few modifications to better fit my needs? I would be grateful and more than happy to pay you for your time.

  8. Looks like we all like this example and all of us want something more.


    Thanx anyway for this….

  9. Very Useful. I’m curious if it would be easy to insert a 3rd row in addition to quantities and sizes that shows where the specific cut is to be installed. I.E. the first cut would have 4 cuts for window 1 and 3 for window 2…

  10. Hello Dick Kusleika,

    I am 16 year and as student that love VBA i follow all your steps… and see you as my master.
    I am for years very interesting in the Cutting Stock problem and find yours one of the best i ever saw!
    But i could never figure out how to make it working by more stock with different lengths.
    If one day you got little time… can you please show it?

    Thank you to read this and for your hard work!


  11. Hi there,
    I was wondering if you have a functioning copy of this you could send through, the zip download is no longer working. I would love to see the construction of the excel file.

  12. That takes me back many years to a time when I was working with a mainframe Linear Programming system (MPSX) with mixed inter options (solving problems for Roger Govier amongst others!). The optimisation of cut stock can be formulated as an Integer programming problem.
    You could probably find the optimum solution using Solver

    There seems to be at least one Excel addin that targets the problem:

  13. Hola, segun veo este metodo no funciona para unos cortes de 1 de 4000,1 de 3000, 2 de 1500 y 2 de 1000 . largo de barra 6000.

    Si tienes la solucion a tal fin agradeceria que me la pases.

  14. Funciono para mi ¿Qué error estás viendo? (It worked for me. What error are you seeing?)

  15. Sí, ya veo. El algoritmo de optimización no es muy bueno. Siempre lleva el corte más grande que se ajuste.

  16. I made a new macro that solves this particular problem. But there are a few caveats. It’s not very well tested, so don’t use it in production. I didn’t do a lot of the error checking that it’s in the original. And it tests every possible combination so it will be really slow if you have more than a few cuts.

    Hice una nueva macro que resuelve este problema en particular. Pero hay algunas advertencias. No está muy bien probado, así que no lo uses en producción. No cometí muchos errores al comprobar que está en el original. Y prueba todas las combinaciones posibles, por lo que será muy lento si tiene más de unos pocos cortes.

  17. La verdad que te pasaste Dick Kusleika , esta muy bien…. Te consulto es posible hacer algo que en verdad tome muchos cortes y optimicen en un stock con medidas dinámicas? He estado buscando mucho este tema y parece que es algo muy complejo de realizar,por lo que me gustaría se es posible que me des una mano.
    Desde ya muchísimas gracias y un abrazo enorme.

  18. Hi Dick,
    This is a shot in the dark but seeing that this thread has had so much success I thought you might have some advice for me with a wood board I’m trying to cut. I know that excel must be able to do this but I have no idea how.

    I have a number of wood boards that I want to cut into a lot of different sizes that I need for my project. I have a list of the exact sizes I need to cut but want to cut them out as efficiently as possible so as not to waste any board.

    Any tips on how to get this done?

    Thanks so much in advance,

  19. You can try the BoardFeetBestFit file I posted a few comments ago, but be sure to read the caveats. When the code test every possible combination, it gets really slow.

  20. How would I flip the column A to B and B to A? My length has to be in Column A and qty of that length is is Column B.


  21. Everywhere there’s a CutArr, you have to change the 0 to 1 and 1 to 0. So CutArr(i,0) would have to be CutArr(i,1), for example.

  22. Thanks for sharing your code.
    I’ve downloaded the last (?) version of it (this one : ) but while doing a quick reading of your code it seems it’s only “cutting” one dimensional ? I mean only the running meters and quantities are being analysed, and then put as optimized as possible into the different boards.
    I need a 2 dimensional code. Where your (wood) panel is a fixed width & height, and the panels you need to cut out or being placed as optimized as possible.
    They may been rotated or not, depending on what kind of wood / execution you have.
    I know it makes it much more difficult than what you wrote, but do you think it’s do-able starting from your code or it’s too complex ?
    Thank you.

    (and very small tip: it’s length and not lenght ;) )

  23. I’ve tried to write the code for area instead of linear a couple times, but never got anywhere. If I were going to do it again, I’d search for “2d cutting stock problem algorithm” and adapt it to VBA.

Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published. Required fields are marked *