简体   繁体   中英

Expanding an Excel formula without referencing the previous cell

I am attempting to use an IF statement to check whether the sum of two cells from another Excel sheet is greater than or equal to 1.

For a sheet called Test1 with the values of interest in column C , this is what I have so far, which works fine: =IF((Test1!C1+Test1!C2>=1),1,0)

In column B on a second sheet that I'll call Test2 , I want to copy this formula down 200,000 rows. However, if the aforementioned formula is in cell B1 , for the formula in B2 I would like the formula to read: =IF((Test1!C3+Test1!C4>=1),1,0)

I want to copy the formula down the column so that the second cell reference in the formula in the first row does not become the first cell reference in the formula in the second row (eg. it would go C1+C2 , then C3+C4 , C5+C6 , etc.).

I have tried manually entering the formula for a few rows, highlighting those, and copying them down but can't get the desired cell reference pattern. If I highlight and drag these first three formulae down another three rows, C4 and C5 are repeated and not in the correct pair.

=IF((Test1!C1+Test1!C2>=1),1,0)

=IF((Test1!C3+Test1!C4>=1),1,0)

=IF((Test1!C5+Test1!C6>=1),1,0)

=IF((Test1!C4+Test1!C5>=1),1,0)

=IF((Test1!C6+Test1!C7>=1),1,0)

=IF((Test1!C8+Test1!C9>=1),1,0)

I have tried using OFFSET() within this formula but couldn't get it to work. I am basically just wanting to add 1 to each of the cell references in the formula, as compared to the previous row (but not to actually add 1 to the value of that cell, as would happen with C1+1 for example).

Any insight would be greatly appreciated!

If you plan on copying this down 200K rows then you will want the absolute simplest formula that accomplishes the stagger. Avoid the volatile OFFSET function or be prepared to spend a lot of time waiting for random calculation cycles to complete. A volatile function will recalculate whenever anything in the workbook changes; not just when something changes that involved the formula in the cell.

 =--(SUM(INDEX(Test1!C:C, (ROW(1:1)-1)*2+1), INDEX(Test1!C:C, (ROW(1:1)-1)*2+2))>=1)

The following formula should do the trick:

=(SUM(INDIRECT("C"&ROW()*2-1);INDIRECT("C"&ROW()*2))>=1)*1

And that's the version using IF :

=IF(SUM(INDIRECT("C"&ZEILE()*2-1);INDIRECT("C"&ROW()*2))>=1;1;0)

您说我基本上只是想在公式中的每个单元格引用上添加“ 1”,但似乎要增加2 ,所以我很困惑,但是一个选择可能是将您现有的公式应用于400,000行,以及=ISODD(ROW())在另一列中使用=ISODD(ROW()) ,然后在该另一列上进行过滤以选择并删除那些显示FALSE

Excel's autofill won't do the 2-cell shift that you're looking for. You can use the functionality that is there.

Put =IF((Test1!C1+Test1!C2>=1),1,0) in the top cell and drag a copy to the second row (it will be =IF((Test1!C2+Test1!C3>=1),1,0) but that's okay). Now, put 'A' and 'B' in the next column. Select all 4 cells and copy them down 400k rows.

Use filter to delete rows flagged with 'B' and delete the blank rows.

(Select blank rows with [F5] click Special and select Blanks , then right-click and delete)

Here is all you need. It's fast and nonvolatile.

=--(SUM(INDEX(Test1!C:C,ROW(1:1)*2-2):INDEX(Test1!C:C,ROW(2:2)*2-2))>=1)

Copy it down as far as you like.

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