breakdown of start and end dates from a list of machines with multiple products

GexcelG

New Member
Joined
May 15, 2018
Messages
7
Hi,
I have a list of products produced by machines per day. each machine can produce multiple products and a product can be produced by multiple machines.
example:
DateMachineProduct
4/2/2018 6:302A
4/3/2018 6:302A
4/4/2018 6:302A
4/5/2018 6:302A
4/8/2018 6:302A
4/9/2018 6:302B
4/10/2018 6:302B
4/11/2018 6:302B
4/12/2018 6:302B
4/13/2018 6:302B
4/14/2018 6:302B
4/15/2018 6:302A
4/16/2018 6:302A
4/16/2018 16:482A
4/17/2018 6:302A
4/18/2018 6:302C
4/19/2018 6:302C
4/20/2018 6:302C
4/2/2018 6:301D
4/3/2018 6:301D
4/4/2018 6:301D
4/5/2018 6:301D
4/8/2018 6:301D
4/9/2018 6:301A
4/10/2018 6:301A
4/11/2018 6:301A
4/12/2018 6:301A
4/13/2018 6:301A
4/14/2018 6:301A
4/15/2018 6:301E
4/16/2018 6:301E
4/16/2018 16:481D
4/17/2018 6:301D
4/18/2018 6:301D
4/19/2018 6:301D
4/20/2018 6:301D

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
I am trying for hours using Pivot table to create a "summary" table, something like this:

2StartEnd
A4/2/2018 6:304/8/2018 6:30
B4/9/2018 6:304/14/2018 6:30
A4/15/2018 6:304/17/2018 6:30
C4/18/2018 6:304/20/2018 6:30
1StartEnd
D4/2/2018 6:304/8/2018 6:30
A4/9/2018 6:304/14/2018 6:30
E4/15/2018 6:304/16/2018 6:30
D4/16/2018 16:484/20/2018 6:30

<colgroup><col><col><col></colgroup><tbody>
</tbody>


Thanks!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this

With Data on Sheet1 in columns A B and C and data has a header

Insert Pivot Table

Drag Machine to Rows section
Drag Product to Rows section
Drag Date into Values
Click on Count of Date in Values
Select Value Field Settings and choose Min
Drag Date into Values
Click on Count of Date in Values
Select Value Field Settings and choose Max

In a blank cell enter a date and time, any date and time
Select that cell
Click on Format Painter and paste over the Pivot Table so all the dates change to dates and times
Widen the column so you can see the output.

This will list the min/max dates per machine per product.

NOTE: You have multiple product groups for each machine, ie Machine 1 has product D occurring twice.
You'll need to isolate these products to have them appear separately on the Pivot Table otherwise it will just group them under one D product.
So you'll need an extra column to isolate each product.
 
Upvote 0
Try this for results starting"E1".
Code:
[COLOR=navy]Sub[/COLOR] MG15May38
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] R [COLOR=navy]As[/COLOR] Range, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Q [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Dim[/COLOR] K [COLOR=navy]As[/COLOR] Variant, Temp [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] dic [COLOR=navy]As[/COLOR] Object, Kk [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Set[/COLOR] Rng = Range("C2", Range("C" & Rows.Count).End(xlUp))
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR=navy]Set[/COLOR] dic = CreateObject("scripting.dictionary")
dic.CompareMode = vbTextCompare
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    dic(Dn.Offset(, -1).Value) = Empty
    [COLOR=navy]If[/COLOR] Not .Exists(Dn.Value) [COLOR=navy]Then[/COLOR]
        .Add Dn.Value, Array(Dn.Offset(, -1).Value, Dn)
    [COLOR=navy]Else[/COLOR]
        Q = .Item(Dn.Value)
          [COLOR=navy]Set[/COLOR] Q(1) = Union(Q(1), Dn)
       .Item(Dn.Value) = Q
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR]
  ReDim Ray(1 To Rng.Count, 1 To 3)
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Kk [COLOR=navy]In[/COLOR] dic.keys
    [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] K [COLOR=navy]In[/COLOR] .keys
         [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] R [COLOR=navy]In[/COLOR] .Item(K)(1).Areas
                [COLOR=navy]If[/COLOR] R(1).Offset(, -1) = Kk [COLOR=navy]Then[/COLOR]
                    [COLOR=navy]If[/COLOR] Not R(1).Offset(, -1) = Temp [COLOR=navy]Then[/COLOR]
                        c = c + 1
                        Ray(c, 2) = "Start": Ray(c, 3) = "End"
                        Ray(c, 1) = R(1).Offset(, -1)
                        Temp = R(1).Offset(, -1)
                    [COLOR=navy]End[/COLOR] If
                     c = c + 1
                     Ray(c, 1) = K:
                     Ray(c, 2) = CDate(R(1).Offset(, -2))
                     Ray(c, 3) = CDate(R(R.Count).Offset(, -2))
                [COLOR=navy]End[/COLOR] If
            [COLOR=navy]Next[/COLOR] R
        [COLOR=navy]Next[/COLOR] K
[COLOR=navy]Next[/COLOR] Kk
[COLOR=navy]End[/COLOR] With
Range("E1").Resize(c, 3).Value = Ray
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]


This may Help!!!

To Save and Run Code:-
Copy code from Thread
In Your Data sheet , Click "Alt+F11" :- Vb Window appears.
From the VBWindow toolbar, Click "Insert" ,"Module":- New VBwindow appears .
Paste Code into this window.
Close Vbwindow.

On sheet Click "Developer tab", Click "Macro". Macro dialog box appears.
Select Macro (with same name) from List.
On the right of Dialog box Click "Run"
The Sheet should now be updated.


Regards Mick
 
Last edited:
Upvote 0
Hi,
It only shows:
12:00:00 AM12:00:00 AM
DateStartEnd
Machine12:00:00 AM12:00:00 AM
4/2/2018 6:30StartEnd
212:00:00 AM12:00:00 AM
112:00:00 AM12:00:00 AM


<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
Maybe the input data is not located at the right place?
Try this for results starting"E1".
Code:
[COLOR=navy]Sub[/COLOR] MG15May38
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] R [COLOR=navy]As[/COLOR] Range, c [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Q [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Dim[/COLOR] K [COLOR=navy]As[/COLOR] Variant, Temp [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] dic [COLOR=navy]As[/COLOR] Object, Kk [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Set[/COLOR] Rng = Range("C2", Range("C" & Rows.Count).End(xlUp))
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR=navy]Set[/COLOR] dic = CreateObject("scripting.dictionary")
dic.CompareMode = vbTextCompare
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    dic(Dn.Offset(, -1).Value) = Empty
    [COLOR=navy]If[/COLOR] Not .Exists(Dn.Value) [COLOR=navy]Then[/COLOR]
        .Add Dn.Value, Array(Dn.Offset(, -1).Value, Dn)
    [COLOR=navy]Else[/COLOR]
        Q = .Item(Dn.Value)
          [COLOR=navy]Set[/COLOR] Q(1) = Union(Q(1), Dn)
       .Item(Dn.Value) = Q
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR]
  ReDim Ray(1 To Rng.Count, 1 To 3)
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Kk [COLOR=navy]In[/COLOR] dic.keys
    [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] K [COLOR=navy]In[/COLOR] .keys
         [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] R [COLOR=navy]In[/COLOR] .Item(K)(1).Areas
                [COLOR=navy]If[/COLOR] R(1).Offset(, -1) = Kk [COLOR=navy]Then[/COLOR]
                    [COLOR=navy]If[/COLOR] Not R(1).Offset(, -1) = Temp [COLOR=navy]Then[/COLOR]
                        c = c + 1
                        Ray(c, 2) = "Start": Ray(c, 3) = "End"
                        Ray(c, 1) = R(1).Offset(, -1)
                        Temp = R(1).Offset(, -1)
                    [COLOR=navy]End[/COLOR] If
                     c = c + 1
                     Ray(c, 1) = K:
                     Ray(c, 2) = CDate(R(1).Offset(, -2))
                     Ray(c, 3) = CDate(R(R.Count).Offset(, -2))
                [COLOR=navy]End[/COLOR] If
            [COLOR=navy]Next[/COLOR] R
        [COLOR=navy]Next[/COLOR] K
[COLOR=navy]Next[/COLOR] Kk
[COLOR=navy]End[/COLOR] With
Range("E1").Resize(c, 3).Value = Ray
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]


This may Help!!!

To Save and Run Code:-
Copy code from Thread
In Your Data sheet , Click "Alt+F11" :- Vb Window appears.
From the VBWindow toolbar, Click "Insert" ,"Module":- New VBwindow appears .
Paste Code into this window.
Close Vbwindow.

On sheet Click "Developer tab", Click "Macro". Macro dialog box appears.
Select Macro (with same name) from List.
On the right of Dialog box Click "Run"
The Sheet should now be updated.


Regards Mick
 
Upvote 0
Hi,
Thanks a lot!
Anyone can think of a way to split the repeated parts automatically? the example i gave was a short and simple one, the original data has alot more repeats...
 
Upvote 0

Forum statistics

Threads
1,216,586
Messages
6,131,573
Members
449,655
Latest member
Anil K Sonawane

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top