Counting cells between matching text

Learden

New Member
Joined
Apr 27, 2022
Messages
2
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello, I searched previous threads and did not find quite what I was looking for. I have a list of analyst initials that are assigned a task on a rotating basis. They would like to know the minimum number of weeks between each assignment so I would like to count the number of cells between two matching references (for example "LM") through out the year and have it return the minimum number of weeks between two appearances of "LM". I am trying to attach a mini sheet using Xl2bb, and it is my first time so I apologize if it is incorrect. It looks really messy.

00. MASTER BATCHING SCHEDULE.xlsm
ABC
1
2Tuesday Thursday
3WEEK OF: Direct Amp BR
4Dec. 27#JP
5Jan. 3GRFCAC
6Jan. 10LMGMH
7Jan. 17*JPMDS
8Jan. 24GRFCAC
9Jan. 31TFSLM
10Feb. 7JPMDS
11Feb. 14GRFCAC
12Feb. 21*GMHGMH
13Feb 28TFSLM
14Mar. 7GMHCAC
15Mar. 14TFSJP
16Mar. 21CACMDS
17Mar. 28*GRFSLC
18Apr. 4TFSJP
19Apr. 11SLCLM
20Apr. 18GRFCAC
21Apr. 25MDSSLC
22May 2GRFLM
23May 9JPMDS
2022
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B5:C31,B56:C56Cell Value="jgl"textNO
B5:C30,B4Cell Valuecontains "JGL"textNO
B6Cell Valuecontains "JGL"textNO
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Give this a try to see if it does what you want. The value returned for "Min Between" represents the number of intervals based on row counting.
MrExcel_20220426.xlsm
ABCDEF
3WEEK OF: Direct Amp BRInitialsMin Between
4Dec. 27#JPCAC2
5Jan. 3GRFCACGMH2
6Jan. 10LMGMHGRF2
7Jan. 17*JPMDSJP3
8Jan. 24GRFCACLM3
9Jan. 31TFSLMMDS2
10Feb. 7JPMDSSLC2
11Feb. 14GRFCACTFS2
12Feb. 21*GMHGMH
1328-FebTFSLM
14Mar. 7GMHCAC
15Mar. 14TFSJP
16Mar. 21CACMDS
17Mar. 28*GRFSLC
18Apr. 4TFSJP
19Apr. 11SLCLM
20Apr. 18GRFCAC
21Apr. 25MDSSLC
222-MayGRFLM
239-MayJPMDS
Sheet3
Cell Formulas
RangeFormula
E4:E11E4=SORT(UNIQUE(FILTERXML("<a><b>"&SUBSTITUTE(TEXTJOIN("|",TRUE,B4:C23),"|","</b><b>")&"</b></a>","//b")))
F4:F11F4=LET(r,FILTER(SEQUENCE(ROWS($A$4:$A$23)),($B$4:$B$23=E4)+($C$4:$C$23=E4)),diffr,INDEX(r,SEQUENCE(ROWS(r)-1,,2))-INDEX(r,SEQUENCE(ROWS(r)-1,,1)),MIN(diffr))
Dynamic array formulas.
 
Upvote 0
And a slight modification will let you see all of the row intervals in cols G:M.
MrExcel_20220426.xlsm
ABCDEFGHIJKLMN
1
2Tuesday Thursday
3WEEK OF: Direct Amp BRInitialsMin BetweenCACGMHGRFJPLMMDSSLCTFS
4Dec. 27#JPCAC236333324
5Jan. 3GRFCACGMH232334622
6Jan. 10LMGMHGRF2365653
7Jan. 17*JPMDSJP323332
8Jan. 24GRFCACLM3425
9Jan. 31TFSLMMDS2
10Feb. 7JPMDSSLC2
11Feb. 14GRFCACTFS2
12Feb. 21*GMHGMH
1328-FebTFSLM
14Mar. 7GMHCAC
15Mar. 14TFSJP
16Mar. 21CACMDS
17Mar. 28*GRFSLC
18Apr. 4TFSJP
19Apr. 11SLCLM
20Apr. 18GRFCAC
21Apr. 25MDSSLC
222-MayGRFLM
239-MayJPMDS
Sheet3
Cell Formulas
RangeFormula
G3:N3G3=TRANSPOSE(E4#)
E4:E11E4=SORT(UNIQUE(FILTERXML("<a><b>"&SUBSTITUTE(TEXTJOIN("|",TRUE,B4:C23),"|","</b><b>")&"</b></a>","//b")))
G4:G8,N4:N6,M4:M5,K4:L7,I4:J8,H4:H5G4=LET(r,FILTER(SEQUENCE(ROWS($A$4:$A$23)),($B$4:$B$23=G$3)+($C$4:$C$23=G$3)),diffr,INDEX(r,SEQUENCE(ROWS(r)-1,,2))-INDEX(r,SEQUENCE(ROWS(r)-1,,1)),diffr)
F4:F11F4=LET(r,FILTER(SEQUENCE(ROWS($A$4:$A$23)),($B$4:$B$23=E4)+($C$4:$C$23=E4)),diffr,INDEX(r,SEQUENCE(ROWS(r)-1,,2))-INDEX(r,SEQUENCE(ROWS(r)-1,,1)),MIN(diffr))
Dynamic array formulas.
 
Upvote 0
Solution
And a slight modification will let you see all of the row intervals in cols G:M.
MrExcel_20220426.xlsm
ABCDEFGHIJKLMN
1
2Tuesday Thursday
3WEEK OF: Direct Amp BRInitialsMin BetweenCACGMHGRFJPLMMDSSLCTFS
4Dec. 27#JPCAC236333324
5Jan. 3GRFCACGMH232334622
6Jan. 10LMGMHGRF2365653
7Jan. 17*JPMDSJP323332
8Jan. 24GRFCACLM3425
9Jan. 31TFSLMMDS2
10Feb. 7JPMDSSLC2
11Feb. 14GRFCACTFS2
12Feb. 21*GMHGMH
1328-FebTFSLM
14Mar. 7GMHCAC
15Mar. 14TFSJP
16Mar. 21CACMDS
17Mar. 28*GRFSLC
18Apr. 4TFSJP
19Apr. 11SLCLM
20Apr. 18GRFCAC
21Apr. 25MDSSLC
222-MayGRFLM
239-MayJPMDS
Sheet3
Cell Formulas
RangeFormula
G3:N3G3=TRANSPOSE(E4#)
E4:E11E4=SORT(UNIQUE(FILTERXML("<a><b>"&SUBSTITUTE(TEXTJOIN("|",TRUE,B4:C23),"|","</b><b>")&"</b></a>","//b")))
G4:G8,N4:N6,M4:M5,K4:L7,I4:J8,H4:H5G4=LET(r,FILTER(SEQUENCE(ROWS($A$4:$A$23)),($B$4:$B$23=G$3)+($C$4:$C$23=G$3)),diffr,INDEX(r,SEQUENCE(ROWS(r)-1,,2))-INDEX(r,SEQUENCE(ROWS(r)-1,,1)),diffr)
F4:F11F4=LET(r,FILTER(SEQUENCE(ROWS($A$4:$A$23)),($B$4:$B$23=E4)+($C$4:$C$23=E4)),diffr,INDEX(r,SEQUENCE(ROWS(r)-1,,2))-INDEX(r,SEQUENCE(ROWS(r)-1,,1)),MIN(diffr))
Dynamic array formulas.
Thank you very much. I would never have been able to sort that out.
 
Upvote 0
You’re welcome…I’m happy to help.
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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