Results 1 to 5 of 5

Thread: Find the number of text repeated in columns of Excel

  1. #1
    Join Date
    Oct 2011
    Posts
    75

    Find the number of text repeated in columns of Excel

    I have an excel sheet. I want to find out the maximum number of times a particular text that has been appeared continuously in a column. Say i have column like this
    • A
    • A
    • A
    • B
    • B
    • B
    • A
    • B
    • B

    I would like to find out whats the maximum number of times "B" has appeared continuously in a column without any other value in between. how do i do it in excel, any help is appreciated.

  2. #2
    Join Date
    May 2011
    Posts
    448

    Re: Find the number of text repeated in columns of Excel

    You can try the below macro code:
    Code:
    Public Function ConsecutiveCount(sStr As String, rng As Range) As Long
    Dim rCell As Range
    Dim iCtr As Long, jCtr As Long
    
    For Each rCell In rng.Cells
    With rCell
    If .Value = sStr Then
    iCtr = iCtr + 1
    jCtr = Application.Max(jCtr, iCtr)
    Else
    iCtr = 0
    End If
    End With
    Next rCell
    ConsecutiveCount = jCtr
    End Function

  3. #3
    Join Date
    May 2011
    Posts
    410

    Re: Find the number of text repeated in columns of Excel

    If you want to optionally allow for case sensitivity, then try the following code:
    Code:
    Public Function ConsecutiveCount(sStr As String, rng As Range, _
    Optional blCaseSensitive As Boolean = False) As Long
    Dim rCell As Range
    Dim iCtr As Long, jCtr As Long
    
    For Each rCell In rng.Cells
    With rCell
    If blCaseSensitive Then
    If .Value = sStr Then
    iCtr = iCtr + 1
    jCtr = Application.Max(jCtr, iCtr)
    Else
    iCtr = 0
    End If
    Else
    If UCase(.Value) = UCase(sStr) Then
    iCtr = iCtr + 1
    jCtr = Application.Max(jCtr, iCtr)
    Else
    iCtr = 0
    End If
    End If
    End With
    Next rCell
    ConsecutiveCount = jCtr
    End Function

  4. #4
    Join Date
    Aug 2011
    Posts
    695

    Re: Find the number of text repeated in columns of Excel

    Here's a formula; assuming the text to look for is in F1, and the cells to investigate are A1:A25. If present, the text appears as the only entry in a cell. =MAX(FREQUENCY(IF(A1:A25=F1,COUNTIF(OFFSET(A1,,,RO W(INDIRECT( "1:"& ROWS(A1:A25)))),"<>"&F1)),ROW(INDIRECT("1:"&R OWS(A1:A25)))-1)). The formula must be entered as one line and finished with <Shift><Ctrl><Enter>, also if edited later. If done correctly, Excel will display the formula in the formula bar enclosed in brackets { }. Don't enter these brackets yourself, they are Excel's way of showing, that the formula is an array formula.

  5. #5
    Join Date
    Nov 2010
    Posts
    503

    Re: Find the number of text repeated in columns of Excel

    Enter "b" (or "B") without quotes in F1, and enter the formula in any cell you want. Remember to finish the formula with <Shift><Ctrl><Enter> (all 3 keys pressed at the same time i.e. press <Shift> and <Ctrl> and while holding them press <Enter>). Release all the 3 keys. If you copy the formula from the post, then select the cell you want the formula to reside in, click the formula bar and press Ctrl+v to paste it to the bar. Go to the end of the first line and press <Delete> to connect the 2 lines and finish with <Shift><Ctrl><Enter>.

Similar Threads

  1. How to convert number to text in excel
    By Jevin in forum Software Development
    Replies: 9
    Last Post: 17-05-2012, 06:42 PM
  2. Replies: 2
    Last Post: 15-02-2012, 08:17 PM
  3. My Text are overlapping with other columns in Excel
    By RajiI in forum MS Office Support
    Replies: 4
    Last Post: 27-01-2012, 07:20 PM
  4. How to find percentage of columns data in Excel
    By Kungfu Pandey in forum Windows Software
    Replies: 2
    Last Post: 07-01-2012, 06:20 PM
  5. How to compare text string of two different columns in Excel
    By Chini mao in forum Windows Software
    Replies: 3
    Last Post: 06-01-2012, 04:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,526,761.13461 seconds with 18 queries