counting a streak of values

jimblimm

Board Regular
Joined
May 11, 2012
Messages
219
i have this formula
=COUNTIFS(B1:B10,"s",B2:B11,"s",B3:B12,"s",B4:B13,"s",B5:B14,"s")

i am wanting to count if the s streaks 4 times....
example

s
s
s
s

is there a shorter formula i can use to do the exact same thing but i can have a variable number of times it should streak in a different cell
example
b1=number of time the "s" repeat/streaks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this:
Code:
Sub Count()
Dim tbl(), s As String, i&

tbl = Application.Transpose(Range("b1:b20"))
s = Join(tbl, "")

For i = 1 To Len(s) - 4
  If Mid(s, i, 4) = "SSSS" Then
    x = x + 1
    ReDim Preserve tbl(1 To x)
    tbl(x) = i + 4
  End If
Next i
Cells(1, 3).Value = UBound(tbl)
End Sub
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,659
Members
450,706
Latest member
LGVBPP

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