Sequencer with Data Range

JonRowland

Active Member
Joined
May 9, 2003
Messages
415
Office Version
  1. 365
Platform
  1. Windows
I'm going to try my best at explaining this as not coming acrosss well in my head.

What I is to conduct a Count of values within Col Z which to include first & last Date (Col A) they appear and last. However the values in Col Z may change at some point but may revert back to the original value at some point. When they revert back I won't the count to restart for this second period.

I want to do this within my VBA project

So Data something like
Col ACol Z
01/01/2020abcd
02/01/2020abcd
03/01/2020fghy
04/01/2020fghy
05/01/2020fghy
06/01/2020abcd
07/01/2020abcd
08/01/2020fghy

Result I would like on a new WkSht
abcd201/01/202002/01/2020
fghy303/01/202005/01/2020
abcd206/01/202007/01/2020
fghy108/01/202008/01/2020
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
with a normal pivottable or with a unique-function and an auxiliary column
Map1
AZAAABACADAEAFAGAH
1Col ACol ZcounterCol Zcounter#minmax
21/01/2020abcd1abcd121/01/20202/01/2020
32/01/2020abcd1fghy233/01/20205/01/2020
43/01/2020fghy2abcd326/01/20207/01/2020
54/01/2020fghy2fghy418/01/20208/01/2020
65/01/2020fghy2---
76/01/2020abcd3---
87/01/2020abcd3---
98/01/2020fghy4---
10---
11---
Blad6
Cell Formulas
RangeFormula
AD1:AE5AD1=UNIQUE(Tabel1[[#All],[Col Z]:[counter]])
AF2:AF11AF2=IF(AE2>0,COUNTIF(Tabel1[counter],AE2),"-")
AG2:AG11AG2=IF(AE2>0,MINIFS(Tabel1[Col A],Tabel1[counter],AE2),"-")
AH2:AH11AH2=IF(AE2>0,MAXIFS(Tabel1[Col A],Tabel1[counter],AE2),"-")
AA2:AA9AA2=SUM(OFFSET([@counter],-1,,,),([@[Col Z]]<>OFFSET([@[Col Z]],-1,,,)))
Dynamic array formulas.
 
Upvote 0
Hi BSALV,

Apologies....I'm not sure what I should entering. I keep getting errors. Although I wold have preferred a VBA solution to include within my project. But will give a go if I can work out what goes where.
 
Upvote 0
VBA Code:
Sub Make_Summary()
     Dim Result()
     With Sheets("Blad3")                                       'your sheet
          Set c = .Range("A1").CurrentRegion                    'currentregion around A1
          a = c.Value2                                          'array A-column
          Z = c.Offset(, 25).Value                              'array Z-column

          ReDim Result(1 To UBound(a), 1 To 4)                  'prepare result-array (oversized)
          For i = 2 To UBound(a)                                'loop through the data
               If i = 2 Or Z(i, 1) <> Z(i - 1, 1) Then          '1st data row or changed Z
                    ptr = ptr + 1                               'increment pointer
                    Result(ptr, 1) = Z(i, 1)                    'new ID
                    Result(ptr, 3) = a(i, 1)                    'new startdate
               End If
               Result(ptr, 2) = Result(ptr, 2) + 1              'increment number
               Result(ptr, 4) = a(i, 1)                         'last date
          Next

          .Range("D1").Resize(ptr, 4).Value = Result            'write result to sheet
     End With
End Sub
 
Upvote 0
Solution
Hi BSALV,

Thank you, this code is perfect and does what I was hoping to do.
VBA Code:
Sub Make_Summary()
     Dim Result()
     With Sheets("Blad3")                                       'your sheet
          Set c = .Range("A1").CurrentRegion                    'currentregion around A1
          a = c.Value2                                          'array A-column
          Z = c.Offset(, 25).Value                              'array Z-column

          ReDim Result(1 To UBound(a), 1 To 4)                  'prepare result-array (oversized)
          For i = 2 To UBound(a)                                'loop through the data
               If i = 2 Or Z(i, 1) <> Z(i - 1, 1) Then          '1st data row or changed Z
                    ptr = ptr + 1                               'increment pointer
                    Result(ptr, 1) = Z(i, 1)                    'new ID
                    Result(ptr, 3) = a(i, 1)                    'new startdate
               End If
               Result(ptr, 2) = Result(ptr, 2) + 1              'increment number
               Result(ptr, 4) = a(i, 1)                         'last date
          Next

          .Range("D1").Resize(ptr, 4).Value = Result            'write result to sheet
     End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

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