how to count duplicates values in a day

AYSHANA

Board Regular
Joined
Oct 16, 2021
Messages
90
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
good day!
i would like to count (how many duplicate pt number I have in a day based on (orders)

thank you.

Book2.xlsx
ABCDEFGHIJKL
1OrdersPT NumberResult Date TimeHOW MANY DUPLICATE PT NUMBER I HAVE IN A DAY BASED ON ORDERS
2BGRPS113/1/2023 22:562023
3BGRPS123/1/2023 13:04
4BGRP123333/1/2023 20:24ROLEJANFEBMARAPRMAY
5BGRPS1233/1/2023 19:21BGRPS WITH BGRPS001
6%XM1233/1/2023 21:53BGRPS WITH %XM002
7BGRPS34553/1/2023 16:24
8BGRPS55563/1/2023 21:22
9BGRP66773/1/2023 20:49
10BGRPS7773/9/2023 16:57
11BGRPS2343/9/2023 3:04
12%XM2343/9/2023 20:54
13BGRPS6663/10/2023 20:32
14BGRPS66553/10/2023 10:22
15BGRPS5433/10/2023 6:36
16BGRPS2453/10/2023 7:40
17BGRPS2453/10/2023 6:43
18BGRP34453/10/2023 23:03
19%XM45563/10/2023 8:51
20%XM55543/1/2023 13:50
Sheet2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B:BCell ValueduplicatestextNO
 
I show you an adaptation:

PHP:
Sub Macro2()
Dim a, C As Range, j%, i&, Tmp
ReDim a(1 To 2, 1 To Range("G4", [g4].End(xlToRight)).Columns.Count - 1)
For i = 2 To [a1].End(xlDown).Row - 1
  Set C = Cells(i, 1)
  If C(1, 2) = C(2, 2) Then
    If C = C(2) Then j = 1 Else j = 2
    Tmp = 0 + Split(C(, 3), "/")(0)
    a(j, Tmp) = 1 + a(j, Tmp)
    i = 1 + i
  End If
Next
[h5].Resize(2, UBound(a, 2)) = a
End Sub
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I show you an adaptation:

PHP:
Sub Macro2()
Dim a, C As Range, j%, i&, Tmp
ReDim a(1 To 2, 1 To Range("G4", [g4].End(xlToRight)).Columns.Count - 1)
For i = 2 To [a1].End(xlDown).Row - 1
  Set C = Cells(i, 1)
  If C(1, 2) = C(2, 2) Then
    If C = C(2) Then j = 1 Else j = 2
    Tmp = 0 + Split(C(, 3), "/")(0)
    a(j, Tmp) = 1 + a(j, Tmp)
    i = 1 + i
  End If
Next
[h5].Resize(2, UBound(a, 2)) = a
End Sub
it is showing error time 13 type mismatch
 
Upvote 0
As I mentioned to you before: I have to see your workbook.
 
Upvote 0
As I mentioned to you before: I have to see your workbook.
BGRPS STATISTICS.xlsm
BEI
1OrdersPT NumberResult Date Time
2BGRPS1148157473/1/2023 22:56
3BGRPS25446873/1/2023 13:04
4BGRP26533623/1/2023 20:24
5BGRPS26772963/1/2023 19:21
6%XM26772963/1/2023 21:53
7BGRPS376192763/1/2023 16:24
8BGRPS486546393/1/2023 21:22
9BGRP527344713/1/2023 20:49
10BGRPS528530393/1/2023 10:36
11BGRPS56864153/1/2023 19:46
12%XM699583603/1/2023 19:36
13BGRPS869992903/1/2023 14:31
14BGRPS9204489563/1/2023 20:50
15BGRPS9208358433/1/2023 13:10
16BGRPS9219029043/1/2023 12:56
17BGRPS9227369883/1/2023 13:03
18BGRP9236136133/1/2023 13:42
19%XM9237048363/1/2023 13:34
20%XM9237249023/1/2023 13:50
21BGRPS9238139873/1/2023 13:06
22BGRPS9238371243/1/2023 11:20
23IAT9238371243/1/2023 0:53
24BGRPS9238597103/1/2023 14:59
25%XM9240848833/1/2023 15:50
26BGRPS9240937523/1/2023 15:48
27BGRPS9240945743/1/2023 15:07
28BGRPS9240960953/1/2023 12:50
29%XM9241051133/1/2023 22:09
30BGRPS9241067813/1/2023 12:32
31BGRPS9241068923/1/2023 19:37
32%XM9241097773/1/2023 11:53
33BGRPS9241110833/1/2023 22:35
34BGRPS104806093/2/2023 16:34
35BGRPS105224253/2/2023 3:56
36%XM11062103/2/2023 7:46
37BGRPS1148157473/2/2023 1:05
38%XM26513513/2/2023 13:07
39%XM26772963/2/2023 5:25
raw daily



Cell Formulas
RangeFormula
A2:A18A2='raw daily'!B2
B2:B18B2='raw daily'!E2
C2:C18C2='raw daily'!I2
 
Upvote 0
I made the macro much more "robust", ie:
Text_1.xlsm
\_____________________/​

a) Start by copying the data from the 'raw daily' sheet.

b) I don't know why you commented before that you had 'text'. But in the dates column you have -actually- dates: so in that sense I went back to version 1 of the macro.

c) When I see more data, I notice that you have not only BGRPS and %XM but also IAT, for example.

d) This forces me to modify the logic of the macro.

e) Finally I incorporated a detail that I had not contemplated: the year that is in cell J2.

Would you comment?...

PHP:
Sub Macro3()
Dim a, C As Range, j%, i&, Tmp
Application.ScreenUpdating = False
Rem ------------------->
Sheets("Sheet1").[a1].CurrentRegion.Offset(1).Delete xlShiftUp
Rem ------------------->
With Sheets("raw daily")
  With .Range("B1", .Range("B1").End(xlDown))
    Union(.Cells, .Columns(4), .Columns(8)).Copy
    Sheets("Sheet1").[a1].PasteSpecial xlPasteValuesAndNumberFormats
  End With
End With
Rem ------------------->
ReDim a(1 To 2, 1 To 12)
For i = 2 To [a1].End(xlDown).Row - 1
  Set C = Cells(i, 1)
  If C(1, 2) = C(2, 2) And Year(C(1, 3)) = Range("J2") Then
    Select Case True
      Case C = "BGRPS" And C(2) = "BGRPS"
        j = 1
        a(j, Month(C(, 3))) = 1 + a(j, Month(C(, 3)))
        i = 1 + i
      Case C = "BGRPS" And C(2) = "%XM"
        j = 2
        a(j, Month(C(, 3))) = 1 + a(j, Month(C(, 3)))
        i = 1 + i
    End Select
  End If
Next
Rem ------------------->
[h5].Resize(2, UBound(a, 2)) = a: Range("A2").Select
End Sub
 
Upvote 0
Solution
i have added another role which is (%xm with %xm) i also extended the range but still it showing subscript out of range



VBA Code:
Sub Macro3()
Dim a, C As Range, j%, i&, Tmp
Application.ScreenUpdating = False
Rem ------------------->
Sheets("DOUBLE").[a1].CurrentRegion.Offset(1).Delete xlShiftUp
Rem ------------------->
With Sheets("raw daily")
  With .Range("B1", .Range("B1").End(xlDown))
    Union(.Cells, .Columns(4), .Columns(8)).Copy
    Sheets("DOUBLE").[a1].PasteSpecial xlPasteValuesAndNumberFormats
  End With
End With
Rem ------------------->
ReDim a(1 To 3, 1 To 12)
For i = 2 To [a1].End(xlDown).Row - 1
  Set C = Cells(i, 1)
  If C(1, 2) = C(2, 2) And Year(C(1, 3)) = Range("J2") Then
    Select Case True
      Case C = "BGRPS" And C(2) = "BGRPS"
        j = 1
        a(j, Month(C(, 3))) = 1 + a(j, Month(C(, 3)))
        i = 1 + i
      Case C = "BGRPS" And C(2) = "%XM"
        j = 2
        a(j, Month(C(, 3))) = 1 + a(j, Month(C(, 3)))
        i = 1 + i
        
        Case C = "%XM" And C(2) = "%XM"
        j = 3
        a(j, Month(C(, 3))) = 1 + a(j, Month(C(, 3)))
        i = 1 + i
            
    End Select
  End If
Next
Rem ------------------->
[h5].Resize(3, UBound(a, 3)) = a: Range("A2").Select
End Sub
 
Upvote 0
Try putting your workbook on an external server (as I did) to see the same as you.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,206
Members
453,022
Latest member
RobertV1609

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