Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2018, 06:11 PM
Marcia's Avatar
Marcia Marcia is offline need help in counting the number of rows that contain 5 consecutive X Windows 7 32bit need help in counting the number of rows that contain 5 consecutive X Office 2007
Expert
need help in counting the number of rows that contain 5 consecutive X
 
Join Date: May 2018
Location: Philippines
Posts: 527
Marcia has a spectacular aura aboutMarcia has a spectacular aura aboutMarcia has a spectacular aura about
Default need help in counting the number of rows that contain 5 consecutive X

Hi. I have a sheet that contains characters combined with "X". I would like to count the number of rows that contain 5 consecutive cells with the letter "X". I found the below array formula that i think would be a jump off point for me to get the number of rows but couldn't seem to come to the correct result when I added COUNTIF before the SUM. If possible, I wouldn't need to add a helper column.


=SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH("X",$A1:$G1)) ,COLUMN($A1:$G1)-COLUMN($A1)+1),IFERROR(SEARCH("X",$A1:$G1),COLUMN( $A1:$G1)-COLUMN($A1)+1))>=5,1))


Thank you.


Um, how do I attach a screenshot in a post?
Attached Files
File Type: xlsx X file.xlsx (14.3 KB, 14 views)

Last edited by Marcia; 11-17-2018 at 08:51 PM.
Reply With Quote
  #2  
Old 11-18-2018, 11:51 PM
xor xor is offline need help in counting the number of rows that contain 5 consecutive X Windows 10 need help in counting the number of rows that contain 5 consecutive X Office 2016
Expert
 
Join Date: Oct 2015
Posts: 1,097
xor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to all
Default

If I enter your formula to H1:H4 I get the results 0,1, 0, 0. You seem to indicate that you get correct result without COUNTIF.

Is that what you say?

Is it important for you to avoid a helper column?
Reply With Quote
  #3  
Old 11-19-2018, 01:04 AM
Marcia's Avatar
Marcia Marcia is offline need help in counting the number of rows that contain 5 consecutive X Windows 7 32bit need help in counting the number of rows that contain 5 consecutive X Office 2007
Expert
need help in counting the number of rows that contain 5 consecutive X
 
Join Date: May 2018
Location: Philippines
Posts: 527
Marcia has a spectacular aura aboutMarcia has a spectacular aura aboutMarcia has a spectacular aura about
Default

Hi Xor. If a helper column (Col H) could be avoided through a straight formula in B6 to return "2", I would prefer that. In the sample sheet, there are 2 rows that are populated with at least five consecutive "x".
Reply With Quote
  #4  
Old 11-19-2018, 01:56 AM
xor xor is offline need help in counting the number of rows that contain 5 consecutive X Windows 10 need help in counting the number of rows that contain 5 consecutive X Office 2016
Expert
 
Join Date: Oct 2015
Posts: 1,097
xor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to all
Default

I have no idea how to solve it without a helper column, but if you already have that solution yourself (as seem to be indicated in your first post) I wouldn't bother you anymore.
Reply With Quote
  #5  
Old 11-19-2018, 08:00 AM
Marcia's Avatar
Marcia Marcia is offline need help in counting the number of rows that contain 5 consecutive X Windows 7 32bit need help in counting the number of rows that contain 5 consecutive X Office 2007
Expert
need help in counting the number of rows that contain 5 consecutive X
 
Join Date: May 2018
Location: Philippines
Posts: 527
Marcia has a spectacular aura aboutMarcia has a spectacular aura aboutMarcia has a spectacular aura about
Default

Quote:
Originally Posted by xor View Post
I have no idea how to solve it without a helper column, but if you already have that solution yourself (as seem to be indicated in your first post) I wouldn't bother you anymore.

It's no bother because I'm learning so much from this forum. I guess I must add a helper column, apply the formula in the first post then make a summation of the results. Thanks..
Reply With Quote
  #6  
Old 11-19-2018, 08:41 AM
xor xor is offline need help in counting the number of rows that contain 5 consecutive X Windows 10 need help in counting the number of rows that contain 5 consecutive X Office 2016
Expert
 
Join Date: Oct 2015
Posts: 1,097
xor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to all
Default

Yes, but I only don't understand how you can use the first formula. As I wrote in #2, for me it returns 0, 1, 0, 0 when entered in H1 and copied down to H4, but as you wrote yourself there are two rows that fulfil the criteria (contain 5 consecutive X.)

Last edited by xor; 11-19-2018 at 11:27 AM.
Reply With Quote
  #7  
Old 11-19-2018, 04:19 PM
Marcia's Avatar
Marcia Marcia is offline need help in counting the number of rows that contain 5 consecutive X Windows 7 32bit need help in counting the number of rows that contain 5 consecutive X Office 2007
Expert
need help in counting the number of rows that contain 5 consecutive X
 
Join Date: May 2018
Location: Philippines
Posts: 527
Marcia has a spectacular aura aboutMarcia has a spectacular aura aboutMarcia has a spectacular aura about
Default

[QUOTE]As I wrote in #2, for me it returns 0, 1, 0, 0 when entered in H1 and copied down to H4, but as you wrote yourself there are two rows that fulfil the criteria (contain 5 consecutive X.)[QUOTE]


Oh.. Maybe I accidentally deleted another X in row 3 because the formula should return 0,1,1,0. I'm re attaching the file.
Attached Files
File Type: xlsx X file.xlsx (14.9 KB, 10 views)
Reply With Quote
  #8  
Old 11-20-2018, 12:03 AM
xor xor is offline need help in counting the number of rows that contain 5 consecutive X Windows 10 need help in counting the number of rows that contain 5 consecutive X Office 2016
Expert
 
Join Date: Oct 2015
Posts: 1,097
xor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to all
Default

In the formula in your first post you used:

=SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH("X",$A1:$G1)) ,COLUMN($A1:$G1)-COLUMN($A1)+1),IFERROR(SEARCH("X",$A1:$G1),COLUMN( $A1:$G1)-COLUMN($A1)+1))>=5,1)) and in the formula in the most recent file:

SUM(IF(FREQUENCY(IF(ISNUMBER(SEARCH("X",$A1:$G1)), COLUMN($A1:$G1)-COLUMN($A1)+1),IF(ISERROR(SEARCH("X",$A1:$G1)),COLUMN($A1:$G1)-COLUMN($A1)+1))>=5,1))

Another possibility is the somewhat shorter formula:

=--(MAX(FREQUENCY(IF(ISNUMBER(SEARCH("X",$A1:$G1)),CO LUMN($A1:$G1)),IF(NOT(ISNUMBER(SEARCH("X",$A1:$G1) )),COLUMN($A1:$G1))))>=5)
Reply With Quote
  #9  
Old 11-20-2018, 04:04 AM
Marcia's Avatar
Marcia Marcia is offline need help in counting the number of rows that contain 5 consecutive X Windows 7 32bit need help in counting the number of rows that contain 5 consecutive X Office 2007
Expert
need help in counting the number of rows that contain 5 consecutive X
 
Join Date: May 2018
Location: Philippines
Posts: 527
Marcia has a spectacular aura aboutMarcia has a spectacular aura aboutMarcia has a spectacular aura about
Default

Thanks Xor, I adopted the shorter formula. Until now I could not make may brain cells to understand the two minuses before the formula. I came across the same functions when counting values in a range except blanks containing formulae. Also, I erroneously thought IFERROR and IF(ERROR) work the same.
Reply With Quote
  #10  
Old 11-25-2018, 05:45 AM
p45cal's Avatar
p45cal p45cal is offline need help in counting the number of rows that contain 5 consecutive X Windows 10 need help in counting the number of rows that contain 5 consecutive X Office 2016
Expert
 
Join Date: Apr 2014
Posts: 871
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

…or write your own user-defined function. See B6 in the attached.
=CountOfRowsWithNOrMoreConsecutiveXs(A1:G4,5)
(Case insensitive)
Code:
Function CountOfRowsWithNOrMoreConsecutiveXs(myRange, N)
Vals = myRange.Value
For rw = 1 To UBound(Vals)
  ThisRowCount = 0
  For colm = 1 To UBound(Vals, 2)
    If InStr(1, UCase(Vals(rw, colm)), "X") > 0 Then ThisRowCount = ThisRowCount + 1 Else ThisRowCount = 0
    If ThisRowCount >= N Then
      RowCount = RowCount + 1
      Exit For
    End If
  Next colm
Next rw
CountOfRowsWithNOrMoreConsecutiveXs = RowCount
End Function
Attached Files
File Type: xlsm msofficeforums40949file.xlsm (15.5 KB, 7 views)
Reply With Quote
  #11  
Old 11-25-2018, 08:41 PM
Marcia's Avatar
Marcia Marcia is offline need help in counting the number of rows that contain 5 consecutive X Windows 7 32bit need help in counting the number of rows that contain 5 consecutive X Office 2007
Expert
need help in counting the number of rows that contain 5 consecutive X
 
Join Date: May 2018
Location: Philippines
Posts: 527
Marcia has a spectacular aura aboutMarcia has a spectacular aura aboutMarcia has a spectacular aura about
Default

Magic Cal, thank you many times.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in counting the number of rows that contain 5 consecutive X how to copy different text from word into excel on consecutive rows mihnea96 Word VBA 4 05-08-2017 12:09 PM
Counting Consecutive Periods In Rows Using Numbers Yaaseen23 Excel 18 03-24-2017 11:15 AM
need help in counting the number of rows that contain 5 consecutive X Counting rows with a macro? Jennifer Murphy Word Tables 1 08-23-2016 03:00 PM
need help in counting the number of rows that contain 5 consecutive X Counting table rows in a page RavenSuzumiya Word Tables 1 06-09-2016 03:38 PM
need help in counting the number of rows that contain 5 consecutive X Problem with consecutive Figure number placements Ian A King Word 2 05-11-2015 10:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft