# How to change row number in function based on a value change

#### psg2002

##### New Member
Hi,

I'm trying to calculate the difference between 2 ranges (each range is in a different tab). I have a table that generates values and I want my function to be able to change the row value based on the return value in the table.

For example, on cell C5, I have the formula '=AVERAGE(Data1!A2:C2)-AVERAGE(Data2!A2:C2)'

If one of the table values, cell H5 returns the value '5', I want my functionion to pick up the value and change the formula to

'=AVERAGE(Data1!A5:C5)-AVERAGE(Data2!A5:C5)'

Is this possible to achieve? thank you so much in advance.

#### Attachments

• excel_screenshot.png
24.3 KB · Views: 7

### Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

#### Habtest

##### Board Regular
Hi there, if I understand correctly, INDIRECT will work, here is an example:

Book1
ABCDEF
1ABC
2123Row2
3234Result2
4345
5456
6567
Sheet1
Cell Formulas
RangeFormula
F3F3=AVERAGE(INDIRECT("Sheet1!A"&F2,TRUE):INDIRECT("Sheet1!C"&F2,TRUE))

#### psg2002

##### New Member
Hi there, if I understand correctly, INDIRECT will work, here is an example:

Book1
ABCDEF
1ABC
2123Row2
3234Result2
4345
5456
6567
Sheet1
Cell Formulas
RangeFormula
F3F3=AVERAGE(INDIRECT("Sheet1!A"&F2,TRUE):INDIRECT("Sheet1!C"&F2,TRUE))
This is perfect! Thank you merci!!

Replies
1
Views
67
Replies
3
Views
45
Replies
6
Views
103
Replies
20
Views
147
Replies
8
Views
79

1,127,905
Messages
5,627,568
Members
416,254
Latest member
Monicamicaela

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back