Finding rows with multiple values in the columns

三世轮回 提交于 2021-01-29 02:45:44

问题


I am attempting to find a way to search rows and find out which ones have multiple values in the rows. For example If I have this:

81  IRENE L MOTZ                        
82  BRITTNEY SUMMERVILLE                        
83  NICK SIRK   33  120             1,859                        
86  DOROTHY TARR                        32    
87  DAVID BRYANT                        
89  WAYNEDALE VAULT                     
90  APRIL HOWARD                        
95  DONA KAHL                       
96  ASHLEY FISHER                       
98  TERRI SULESKI                       
99  SCOTTSVILLE VAULT                       
104 CHRISTINE WIECHART      564             
105 KAYLENE DUNCAN      7               
106 LINDA NETHERTON                     
107 DIANNA MAY              336     
108 DIXIE HETTINGER     596             
110 JIM MELVIN      26              
111 LASHAWNYA BREWER        181             
112 LOIS COLEMAN        283             
113 KRISTIN FRIEND      827             
115 BRANDI QUDUS        2,106

You can see that the row starting with 83 has three values in the columns that follow the name. While the others in this example only have one value. I need to be able to find the rows that have multiple values, then I'm going to perform some actions on the values in the columns (mostly just adding them together and then subtracting the total from a previously calculated number). I don't have any code at the moment, if some one could point me in the right direction that would be great. I though maybe trying to do it with IF ELSEIF statements, but that just seemed sloppy to me.


回答1:


Assuming your data range starts at B1, you enter in A1 the formula

=COUNT(B1:I1)-1

(you mentioned data would go up to column H, I moved it one column to the right) or

=COUNT(C1:I1)

This gives 0 for the first row, as expected. Copying and pasting the formula downwards gives the number you are looking for, for each row (all values <=1, except for row 3). Then you can filter, or perform other actions.

For instance, to get the sum of all numbers in the row (as you mentioned), you would use

=SUMPRODUCT(--(ISNUMBER(C1:I1)),C1:I1)

If you want to calculate this only for rows having more than one number, you can nest this formula inside an IF(B1>1,...

Notes:

  1. This avoids using VBA.

  2. I have copied the data you posted, then pasted in cell B1 of a new sheet. Then Data -> Text to Columns -> Delimited -> (Tick Space). This rendered data in separate columns, as it appears you be your case.

  3. The ranges referred to should be modified, depending on the organization and location of your data.



来源:https://stackoverflow.com/questions/20761930/finding-rows-with-multiple-values-in-the-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!