简体   繁体   English

Excel问题 - 计算值作为单元格引用

[英]Excel Problems- Calculated value as a cell reference

I'm relatively new to excel programming. 我对excel编程比较陌生。 I'm working on making a spread sheet that shows exponential decay. 我正在制作一张显示指数衰减的电子表格。 I have one column (A1:A1000) of 1000 random numbers between 1 & 10 using the TRUNC(RAND()*10,0) in each cell. 我在每个单元格中使用TRUNC(RAND()* 10,0)在1和10之间有一列1000(A1:A1000)1000个随机数。 The next Column (B1:B1000) has a logic mask =IF(A1=0,1,0) , where if the value in the A cell is 0, then the B cell shows a 1. Next, to find the number of 0's in the A column, I have the next column taking the sum of B1:B1000, which returns the number of 0's that showed up in the first column. 下一列(B1:B1000)具有逻辑掩码= IF(A1 = 0,1,0),其中如果A单元格中的值为0,则B单元格显示1.接下来,查找数量A列中的0,我有下一列取B1:B1000的总和,它返回第一列中显示的0的数量。 I'm sure there's an easier way to do that, but this seems to work fine. 我确信有一种更简单的方法可以做到这一点,但这似乎工作得很好。

Here's my problem, hopefully it's clear what I'm asking: 这是我的问题,希望很清楚我在问什么:

Next, I want to take the sum of the logic column (B) from B1:B(1000- the value of the sum from (B1:1000)) in the cell below the cell that calculates sum(B1:B1000). 接下来,我想从计算和(B1:B1000)的单元格下方的单元格中取B1:B(1000-来自(B1:1000)的和的值)的逻辑列(B)的总和。 Is there a way to to algebra in a cell formula to reference a cell? 有没有办法在单元格公式中使用代数来引用单元格? More simply, if I want to refer to A3, for example, is there a way to input something like A(2+1) to get A3? 更简单地说,如果我想参考A3,例如,有没有办法输入类似A(2 + 1)的东西来获得A3? Does this make sense? 这有意义吗?

You can very easily do, in VBA: 你可以很容易地在VBA中做到:

ActiveCell.Formula = "=A" & (2+1) & "+15"

In Excel: 在Excel中:

=INDIRECT(ADDRESS(2+1, COLUMN(A1)))+15

This will set the formula to "=A3+15". 这会将公式设置为“= A3 + 15”。 Generally, this is best done with variables, so remember to do that. 通常,这最好用变量完成,所以记住这样做。

In Excel, and as pointed out by Eric, you can write the referance to the cells just like normal strings thanks to INDIRECT() function. 在Excel中,正如Eric所指出的,由于INDIRECT()函数,您可以像普通字符串一样将参考文写入单元格。

Just make sure that the string passed to INDIRECT() is a valid cell reference. 只需确保传递给INDIRECT()的字符串是有效的单元格引用。

For example : 例如 :

=SUM(INDIRECT("B" & 2+7*(H2-1)):INDIRECT("B"&(2+7*H2)-1))

Here, I sum 7 lines for each week ( H2 ). 在这里,我每周总计7行( H2 )。 It gives the sum of B2:B8 , B9:B15 , B16:B22 , etc. 它给出了B2:B8的总和B2:B8B9:B15B16:B22等。

Hope my example will help you figure out how to use it in real situation. 希望我的例子可以帮助你弄清楚如何在真实情况下使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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