so I have the following formula:

=sumif(Gx:Gy,50,Px:Py)

where x and y are numbers I have entered.

However, I want the numbers in the above formula to be determined by the values in another cell (let’s say the x to be determined by the value in cell A1, and the y to be determined by the value in cell A2). So if A1 contained 3 and A2 contained 5 then the formula would be =sumif(G3:G5,50,P3:P5). How would I go about doing this? Thanks

You can do this with a combination of `SUMIF`

and `INDIRECT`

The formula in F6 below is:

```
=SUMIF(INDIRECT("A"&F9&":A"&G9),50,INDIRECT("B"&F9&":B"&G9))
```

### Answer：

You could use OFFSET

```
=SUMIF(OFFSET(G1,A1,,A2-A1,1),50,OFFSET(P1,A1,,A2-A1,1))
```

You probably want some handling to ensure X<=Y.

That might look like:

```
=IF(A1<=A2,SUMIF(OFFSET(G1,A1,,A2-A1,1),50,OFFSET(P1,A1,,A2-A1,1)),"")
```

Tags: excelexcel