• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Creating a monthly defect pareto

Arthur Ramaglie

New Member
I have a spreadsheet of defect descriptions that include a part number, the day the defect was found, and the number of defects that occurred for that observation, among other information. What I want to do is search the column with part numbers until I find a certain part number, obtain the defect count for that instance, and continue on until the end of the data. Then I want to calculate the number of defects that occurred for that part number per month, and create a table on another sheet. There can be multiples of the same date for a part number, and there are also dates missing, but the dates are listed in ascending order. I am a beginner VBA programmer. This is what I have so far.
The part numbers are in column C, the dates are in column A, and the counts are in column F
Code:
Sub Macro8()
Dim Count As Integer, TotalCount As Integer, EnterAssembly As String
    Sheets("Defects").Select
    TotalCount = 0
    EnterAssembly = "xxxxxxx"
    i = 2
    Do Until ActiveCell.Value = vbNullString
        Range("Ci").Select
        If ActiveCell.Value = EnterAssembly Then
            Count = ActiveCell.Offset(0, 3)
            TotalCount = TotalCount + Count
        Else
            i = i + 1
        End If
    Loop
End Sub

I have also tried this, but this doesn't work either.
Code:
Sub GetDefects()
Dim EnterAssembly As String, EnterDate As Date, dtDate1 As Date, i As Integer, j as integer, MyRange as Range

'Obain values for assembly and start date
    EnterDate = InputBox("Enter the date that the pareto will start from.")
    EnterAssembly = InputBox("Enter the assembly number.")
'Calculate # of defects per month
    Windows("Running daily Inspection Breakdown.xlsx").Activate
    j = 0
    cCount = 0
    Do Until ActiveCell.Value = vbNullString
        i = 2
        Do Until ActiveCell.Value = vbNullString
            Set MyRange = Range("Ai").Select
            dDate1 = MyRange.Value
            If dDate1 <= WorksheetFunction.EoMonth(EnterDate, j) Then
                cCount = cCount + MyRange.Offset(0, 5)
                i = i + 1
            Else
                Windows("Pareto Macro.xlsm").Activate
                Range("$B$(j+4)").Select
                cCount = Range("$B$(j+4)").Value
                Exit Do
            End If
        Loop
        j = j + 1
    Loop
End Sub
Any advice would be much appreciated.

Moved to VBA Macros
 
Arthur

Firstly, Welcome to the Chandoo.org Forums

Have you thought about simply using a Pivot table to do what you want ?

Could you upload a sample file to assist us to assist you ?
 
Thank you. Im not too familiar with Pivot tables, but I did try using one. But I was getting bizarre results because there are multiple places where the date, part number, and count are all the same, but they represent different defects, which wasn't being represented with the pivot table. Attached is a piece of the datasheet that shows how it is formatted. However the real file is over 30,000 rows. Thank you again.
 

Attachments

  • Copy of Copy of Pareto Macro.xlsm
    32.8 KB · Views: 4
Try the following
On sheet2 select you data include headings
Insert, Pivot Table
New Worksheet
In the Pivot Table Fields Dialog
Drag Date to Rows
Drag Assembley Number to Column
Drag Area of Defect to Column
Drag Count to Sum Values
Right Click on the Dates, Group
Select months, Ok

This should give you 99% of what your after
See attached
 

Attachments

  • Copy of Copy of Pareto Macro.xlsm
    27.9 KB · Views: 8
ok it works on the example that you sent me, but when I apply it to the entire datasheet, it is only counting the rows. i.e. if for one date, the count number is 7, it is only counting that single occurrence as 1 in the pivot table.
 
You can sort by a field, Right click the field and select Sort
You can add a Pivot Chart also
 
Back
Top