Nic
Nic

Reputation:

Excel Problems- Calculated value as a cell reference

I'm relatively new to excel programming. 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. 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. 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). 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? Does this make sense?

Upvotes: 4

Views: 34366

Answers (2)

Jahus
Jahus

Reputation: 73

In Excel, and as pointed out by Eric, you can write the referance to the cells just like normal strings thanks to INDIRECT() function.

Just make sure that the string passed to INDIRECT() is a valid cell reference.

For example :

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

Here, I sum 7 lines for each week (H2). It gives the sum of B2:B8, B9:B15, B16:B22, etc.

Hope my example will help you figure out how to use it in real situation.

Upvotes: 0

Eric
Eric

Reputation: 95133

You can very easily do, in VBA:

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

In Excel:

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

This will set the formula to "=A3+15". Generally, this is best done with variables, so remember to do that.

Upvotes: 12

Related Questions