Count - specific consecutive order

no need

New Member
Joined
Dec 1, 2023
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I'm making an excel that represents a calendar.
- In columns, we have months from B to M (B2 being January and M2 being December).
- In rows, we have days (A3 is day 1 and A33 is day 31).
For each cell within B3:M33, we'll input either A or B.
January, March, May, July, August, October and December will all have inputs until row 33 included as they have 31 days/month
April, June, September and November will all have inputs until row 32 as they have 30 days/month
February will have inputs until row 30 as it will have 29 days in 2024.
I'm looking for a formula or a macro that does the following:
If the input "B" is consecutively entered for more than 89 times, then display this message "blabla". Else, display this "albalb".
The complexity 1 I face is that, I can't manage to find a formula that takes this specific order as the definition of consecutiveness.
For instance, after B33 (i.e day 31 of Jan), it's not B32 but C3 (i.e day 1 of Feb).
The complexity 2 I face is that, what I have tried counts across B3:M33 without taking the consecutive order into account (like a countif).
Anybody can help? So far, below my (chatgpt's) last trial:
VBA Code:
Sub CheckConsecutivity()

Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("Planning") ' Change "Sheet1" to your sheet name



Dim cell As Range

Dim consecutiveCount As Integer

consecutiveCount = 0



' Specify the order of cells

Dim cellOrder As Variant

cellOrder = Array("B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", "B11", "B12", "B13", "B14", "B15", "B16", "B17", "B18", "B19", "B20", "B21", "B22", "B23", "B24", "B25", "B26", "B27", "B28", "B29", "B30", "B31", "B32", "B33", _

"C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C11", "C12", "C13", "C14", "C15", "C16", "C17", "C18", "C19", "C20", "C21", "C22", "C23", "C24", "C25", "C26", "C27", "C28", "C29", "C30", "C31", _

"D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15", "D16", "D17", "D18", "D19", "D20", "D21", "D22", "D23", "D24", "D25", "D26", "D27", "D28", "D29", "D30", "D31", "D32", "D33", _

"E3", "E4", "E5", "E6", "E7", "E8", "E9", "E10", "E11", "E12", "E13", "E14", "E15", "E16", "E17", "E18", "E19", "E20", "E21", "E22", "E23", "E24", "E25", "E26", "E27", "E28", "E29", "E30", "E31", _

"F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24", "F25", "F26", "F27", "F28", "F29", "F30", "F31", "F32", "F33", _

"G3", "G4", "G5", "G6", "G7", "G8", "G9", "G10", "G11", "G12", "G13", "G14", "G15", "G16", "G17", "G18", "G19", "G20", "G21", "G22", "G23", "G24", "G25", "G26", "G27", "G28", "G29", "G30", "G31", "G32", _

"H3", "H4", "H5", "H6", "H7", "H8", "H9", "H10", "H11", "H12", "H13", "H14", "H15", "H16", "H17", "H18", "H19", "H20", "H21", "H22", "H23", "H24", "H25", "H26", "H27", "H28", "H29", "H30", "H31", "H32", "H33", _

"I3", "I4", "I5", "I6", "I7", "I8", "I9", "I10", "I11", "I12", "I13", "I14", "I15", "I16", "I17", "I18", "I19", "I20", "I21", "I22", "I23", "I24", "I25", "I26", "I27", "I28", "I29", "I30", "I31", "I32", "I33", _

"J3", "J4", "J5", "J6", "J7", "J8", "J9", "J10", "J11", "J12", "J13", "J14", "J15", "J16", "J17", "J18", "J19", "J20", "J21", "J22", "J23", "J24", "J25", "J26", "J27", "J28", "J29", "J30", "J31", "J32", _

"K3", "K4", "K5", "K6", "K7", "K8", "K9", "K10", "K11", "K12", "K13", "K14", "K15", "K16", "K17", "K18", "K19", "K20", "K21", "K22", "K23", "K24", "K25", "K26", "K27", "K28", "K29", "K30", "K31", "K32", "K33", _

"L3", "L4", "L5", "L6", "L7", "L8", "L9", "L10", "L11", "L12", "L13", "L14", "L15", "L16", "L17", "L18", "L19", "L20", "L21", "L22", "L23", "L24", "L25", "L26", "L27", "L28", "L29", "L30", "L31", "L32", _

"M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10", "M11", "M12", "M13", "M14", "M15", "M16", "M17", "M18", "M19", "M20", "M21", "M22", "M23", "M24", "M25", "M26", "M27", "M28", "M29", "M30", "M31", "M32", "M33")



For Each cellName In cellOrder

Set cell = ws.Range(cellName)

If cell.Value = "B" Then

consecutiveCount = consecutiveCount + 1

If consecutiveCount > 89 Then

ws.Range("O13").Value = "blabla"

ws.Range("O13").Interior.Color = RGB(255, 0, 0) ' Red color

Exit Sub

End If

Else

consecutiveCount = 0

End If

Next cellName



' If the loop completes without meeting the condition

ws.Range("O13").Value = "albalb"

ws.Range("O13").Interior.Color = RGB(0, 255, 0) ' Green color

End Sub
 
Last edited by a moderator:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Here is a function that will work in excel 2019:
Result in B36

Libro1
ABCDEFGHIJKLM
2ene-24feb-24mar-24abr-24may-24jun-24jul-24ago-24sep-24oct-24nov-24dic-24
31ABBBBABBBAAA
42ABBBAABABBAB
53ABBBABABBBAA
64ABBBABAABBAA
75ABBBBBABAAAA
86ABBBABABBAAA
97ABBBAABAABAA
108BBBAABBABAAB
119BBBBAABBAABB
1210BBBBABAAABAB
1311BBBBABAABABB
1412BBBABBBAAAAA
1513BBBBBABBABAB
1614BBBABABAABBB
1715BBBBABAAABBA
1816BBBBABBBBAAA
1917BBBAABABBABA
2018BBBABAAAABAB
2119BBBAAABAAAAB
2220BBBABABBAAAB
2321BBBBABABABBB
2422BBBBBABABAAB
2523BBBAAAABBABB
2624BBBBBAAABAAA
2725BBBABBABAAAA
2826BBBBBAAABBBB
2927BBBAAAABABBB
3028BBBABABBBAAA
3129BBBAAAAAAABB
3230BBBAABAABBB
3331BBBBBAB
34
35
36blabla
Hoja1
Cell Formulas
RangeFormula
B36B36=IF(IFERROR(SEARCH("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",CONCAT(B3:B33,C3:C33,D3:D33,E3:E33,F3:F33,G3:G33,H3:H33,I3:I33,J3:J33,K3:K33,L3:L33,M3:M33)),0),"blabla","albalb")
 
Upvote 0
A slightly cleaner solution:

Excel Formula:
=SI(SI.ERROR(HALLAR(CONCAT(SI(FILA(INDIRECTO("A1:A90"));"B";""));CONCAT(B3:B33;C3:C33;D3:D33;E3:E33;F3:F33;G3:G33;H3:H33;I3:I33;J3:J33;K3:K33;L3:L33;M3:M33));0);"blabla";"albalb")
 
Upvote 0
Another option
Excel Formula:
=IF(ISNUMBER(SEARCH(REPT("B",90),CONCAT(TRANSPOSE(B3:M33)))),"blabla","albalb")
 
Upvote 0
Here is a function that will work in excel 2019:
Result in B36

Libro1
ABCDEFGHIJKLM
2ene-24feb-24mar-24abr-24may-24jun-24jul-24ago-24sep-24oct-24nov-24dic-24
31ABBBBABBBAAA
42ABBBAABABBAB
53ABBBABABBBAA
64ABBBABAABBAA
75ABBBBBABAAAA
86ABBBABABBAAA
97ABBBAABAABAA
108BBBAABBABAAB
119BBBBAABBAABB
1210BBBBABAAABAB
1311BBBBABAABABB
1412BBBABBBAAAAA
1513BBBBBABBABAB
1614BBBABABAABBB
1715BBBBABAAABBA
1816BBBBABBBBAAA
1917BBBAABABBABA
2018BBBABAAAABAB
2119BBBAAABAAAAB
2220BBBABABBAAAB
2321BBBBABABABBB
2422BBBBBABABAAB
2523BBBAAAABBABB
2624BBBBBAAABAAA
2725BBBABBABAAAA
2826BBBBBAAABBBB
2927BBBAAAABABBB
3028BBBABABBBAAA
3129BBBAAAAAAABB
3230BBBAABAABBB
3331BBBBBAB
34
35
36blabla
Hoja1
Cell Formulas
RangeFormula
B36B36=IF(IFERROR(SEARCH("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",CONCAT(B3:B33,C3:C33,D3:D33,E3:E33,F3:F33,G3:G33,H3:H33,I3:I33,J3:J33,K3:K33,L3:L33,M3:M33)),0),"blabla","albalb")
Thank you so much, I have tested and it workd perfectly. The only thing is that this wouldn't work with longer words as there would be too many characters for the formula to work. Yet, creative and working solution.
 
Upvote 0
The only thing is that this wouldn't work with longer words as there would be too many characters for the formula to work.
They would need to be very long words wouldn't they? :eek:
Did you have something in mind? I think the suggestion could likely be adapted if either CONCAT or REPT was likely to exceed its character limit.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,112
Members
453,021
Latest member
Justyna P

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