从一个单元格移动到另一个单元格,并计算两个数据之间的行数 [英] Move from one cell to another and count the number of rows in between two data

查看:86
本文介绍了从一个单元格移动到另一个单元格,并计算两个数据之间的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列有250行。在这些行中,所馈送的数据是0和1。我需要找到任何两个1之间的行数。我需要为同一个宏编写一个宏。例如:如果我的列如下:

  A1 0 B1 2 
A2 0 B2 2
A3 0
A4 1
A5 0
A6 0
A7 1
A8 0
A9 0
A10 1

我想要的是检查从A1到A10的整个列。从A1开始,我的程序将检查'1',它在A4中找到,它将继续向下移动,直到找到另一个'1'。这里会移动到A7。现在结果应该是在中间的行数,即在这种情况下为2。这个结果应该粘贴在另一个列中,让我们说B1。这个过程需要继续,直到光标到达B10行。请帮助。

解决方案

使用Control + Shift + Enter输入以使其成为数组公式。在B1

  = LARGE((ROW($ A $ 1:$ A $ 10))*($ A $ 1:$ A $ 10 = 1),SUM( - ($ A $ 1:$ A $ 10 = 1)) - (ROW())) - 大((ROW($ A $ 1:$ A $ 10))*($ A $ 1:$ A $ 10 = 1),SUM( - ($ A $ 1:$ A $ 10 = 1)) - (ROW() -  1)) -  1 

并填写。该公式包括减去两个LARGE函数,然后从结果中减去1。



LARGE函数的第一个参数是一个数组,它返回每个条目的行号,包含一个1。

 (ROW($ A $ 1:$ A $ 10))*($ A $ 1:$ A $ 10 = 1)

LARGE函数的第二个参数是一个SUM数组公式,用一个1,然后减去当前行号(或当前行号-1)。对于B1中的公式,这将返回3-1(或2,所有条目的计数,一(3)少于行号(1))。



对于第二个LARGE函数,第二个参数将返回3-0(3)。



所有这些说,给我包含一个条目的条目的第二行1并减去包含1的条目的第3行。



当您填写到B2时,这将变为:给我第一行的条目,包含1并减去第二大行。



最后,我们从整个事物中减去1,使结果独占(而不是包含)包含1的行



我知道你要求一个宏,但你可能会找到更合适的公式。


I have got one column with 250 rows. The data fed is 0 and 1 randomly in these rows. I need to find the number of row between any two 1's. I need to write a macro for the same.For ex: if my column is as follow:

       A1 0        B1 2
       A2 0        B2 2
       A3 0        
       A4 1
       A5 0 
       A6 0 
       A7 1
       A8 0 
       A9 0 
      A10 1

What I want is to check the entire column from A1 to A10. Starting from A1, my program would check for '1', it found in A4, it will continue to move down until it finds another '1'. Here it will move to A7. Now the result should be 'number of rows in-between' i.e 2 in this case. This result should be pasted in another column, lets say B1. This process need to be continued till my cursor reaches the B10 row. Please help.

解决方案

Enter with Control+Shift+Enter to make it an array formula. In B1

=LARGE((ROW($A$1:$A$10))*($A$1:$A$10=1),SUM(--($A$1:$A$10=1))-(ROW()))-LARGE((ROW($A$1:$A$10))*($A$1:$A$10=1),SUM(--($A$1:$A$10=1))-(ROW()-1))-1

and fill down. The formula consists of subtracting two LARGE functions and then subtracting 1 from the results.

The first argument to the LARGE functions is an array that returns the row number for every entry that contains a 1.

(ROW($A$1:$A$10))*($A$1:$A$10=1)

The second argument to the LARGE functions is a SUM array formula that counts all the entries with a 1, then subtracts the current row number (or the current row number -1). For a formula in B1, this would return 3-1 (or 2, the count of all entries with one (3) less the row number (1)).

For the second LARGE function, the second argument would return 3-0 (3).

All of that says, give me the 2nd largest row for the entries that contain a 1 and subtract the 3rd largest row for the entries that contain a 1.

When you fill down to B2, that becomes: give me the 1st largest row for the entries that contain a 1 and subtract the 2nd largest row.

Finally we subtract 1 from the whole thing to make the result exclusive (rather than inclusive) of the rows that contain the 1's.

I know you asked for a macro, but you may find formulas more suitable.

这篇关于从一个单元格移动到另一个单元格,并计算两个数据之间的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆