View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Count consecutive characters within a cell

One way, using a User Define Function:

Public Function XOrMore( _
ByVal sTest As String, _
ByVal X As Long) As Boolean
Dim nCount As Long
Dim i As Long
For i = 2 To Len(sTest)
If Mid(sTest, i - 1, 1) = Mid(sTest, i, 1) Then
nCount = nCount + 1
If nCount = X - 1 Then Exit For
Else
nCount = 0
End If
Next i
XOrMore = nCount = X - 1
End Function

Call as =XorMore(A1, 4)

if you're not familiar with UDFs, see

http://www.mvps.org/dmcritchie/excel/getstarted.htm

In article ,
Jshendel wrote:

I have a genetic sequence such as:
AATTCAGTTACTTTTGCA

I need a formula that will tell me if this cell has a run of 4 or more
consecutive letters. The run can consist of 4 or more A, T, C, or G.

The above example can return simply as "yes" or can be as complex as "this
cell has 4 consecutive T's"

Thanks,
Josh