How to count consecutive specific characters in a range excel

Mavri

New Member
Joined
Nov 30, 2022
Messages
23
Office Version
  1. 2016
Platform
  1. Windows
Hello,everyone.
I need to count consecutive specific characters in an excel range.For example:
+N++NNDONNDODO

How do I count how many times "N" is appearing more than once consecutively?And what is number of maximum consecutive appearing of an "N"?
I need two different formulas.

Thanks in advance!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

With your data in range B2 to L2, you can test following two Array Formulas
Excel Formula:
=SUM(IF(FREQUENCY(IF(B2:L2="N",COLUMN(B2:L2)),IF(B2:L2<>"N",COLUMN(B2:L2)))>=2,1,0))
=MAX(FREQUENCY(IF(B2:L2="N",COLUMN(B2:L2)),IF(B2:L2<>"N",COLUMN(B2:L2))))
 
Upvote 0
It doesn't work .... is not a very explicit answer ...

What is the result you are getting ???
 
Upvote 0
VBA solution. Assumed your range is B2:L2

Output in P1:P2

VBA Code:
Sub jec()
 Dim r, x As Long, y As Long, s As Long
 For Each r In Range("B2:L2")
    If r.Offset(, -1) = "N" And r = "N" And r.Offset(, 1) <> "N" Then x = x + 1
    If r = "N" Then
       y = y + 1
    Else
      s = IIf(y > s, y, s): y = 0
    End If
 Next
 Range("P1:P2") = Application.Transpose(Array(x, s))
End Sub
 
Upvote 0
Forgot to add the obvious reminder about Array Formulas:

Instead of the standard Enter key .... you do need to use simultaneously the three keys : Control + Shift + Enter

Most probably : "It does not work" will happily turn into : "It does work" :)
 
Upvote 0

Forum statistics

Threads
1,215,420
Messages
6,124,801
Members
449,189
Latest member
kristinh

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