简体   繁体   中英

Excel Row Count Formula - Error

I have this Formula:

=ROW()-MATCH(LOOKUP(2,1/(D$1:INDIRECT("D" & ROW() -1)<>""),D$1:INDIRECT("D" & ROW() -1)),D$1:INDIRECT("D" & ROW() -1),0)

In order to speed up counting days between events, it simply finds the last non empty cell above it and subtracts its row value from the row value before the current cell. It was going fine for about a month and then suddenly I started getting random numbers.

Example of random data

The 730 was the first error I hit so I decided to spam the formula and see what my results are and as you can see they are quite inconsistent.

Any help at all would be greatly appreciated

Each cell has the proper column data input into the formula that is not the issue.

I believe your problem arises from the fact that the lookup function returns the first row with the searched value.

In the example data you gave row 740, 745, and 748 are all preceded by a 1 and they all count back to row 738 (which is the first row in the column with a 1 in it).

If you want to try a cleaner formula that doesn't rely on lookups try:

=ROW()-1-SUM(D1:INDIRECT("D" & ROW()-1))

If all previous rows are accurate (and row 1 = 0), then this should correctly count the number of days since your last event.

尝试一下,

=row()-match(1e99, d$1:index(d:d, row()-1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM