Really having trouble figuring out something that should be an easy VBA loop that sums resulting numbers - any input appreciated

  • I am working with an Excel Workbook that is used to record measurements. Each Sheet is a copy of the master for a new lot to record measurements for that lot. I am trying to automatically calculate the Cpk the same way Minitab does and unfortunately Minitab doesn't use a normal standard deviation, it uses Stdev(within). I need help figuring out why my code isn't working becuase it appears so simple but it isn't summing the loop correctly.



    The way this workbook is set-up, no matter how many results there are I can sum them simply with the code =Sum(Inspection_Record3[1]) and this will sum all the results under the 1 column. I could do the same thing for an average,a count, etc. In an outside cell I use the count function so then in my code I can refer to that count, subtract two and I have all the values I need to use to get my absolute values. The issue is to get the stdev(within) I need to find the moving range in the background. To do this you take the absolute value of the first result minus the second result, add that to the absolute value of the second minus the third, and so on for all the results and get the sum of all these numbers. I can't seem to make this work at all. I thought I knew how to get it and when I hit play in VBA it scrolls down to all the proper cells and stops where it is supposed to but when I try typing the function =josh() in a cell it says "Microsoft Excel cannot calculate a formula. There is a circular reference in an open workbook, but the references that cause it cannot be listed for you. Try editing the last formula you entered or removing it with the Undo command". Then it just puts 0 in the cell. I swear I have done loops like this before where the sum in the loop just keeps growing until the loop is over. I have no idea why this isn't working. Any help would be soooo greatly appreciated. I know it is something small I'm missing I just can't seem to see it. My code is below.


    Thanks Everyone who took the time to read this and thanks in advance for any assistance you may be able to provide.


    Regards,


    Josh

    Thanks again everyone!

  • I figured it out. I have no idea why I can't get it to run as a function but as a sub it works fine with this code:


Participate now!

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