Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to check which cells are specifically used in an Excel formula?

I have the following conundrum in Excel:

A1: 1
A2: 2
A3: 3

B1: =average(A1:A2)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In C1:C3, I want Excel to check if the corresponding cell in column A was used in the average calculation, and if it was, display the value of the cell, and, if not, display blank (ex. A1 was used in the average, therefore display the value of A1, which is 1).

Is there a way to do this? I have tried to use the "countif" formula (=countif(b1,a1)), but have not been able to get it work.

Thank you.

>Solution :

You could use something like:

=IF(ISNUMBER(FIND(ADDRESS(ROW(A1), COLUMN(A1), 4), FORMULATEXT(B$1))), A1, "")

and copied down.

However, this would not necessarily prevent a false positive if the formula contained a string which resembled a reference: for example, if the formula in B1 were instead:

=IF(AVERAGE(A1:A2) = 0, 1, "A3")

then the row 3 formula would incorrectly return 3.

More robust would be:

=LET(
    φ, ADDRESS(ROW(A1), COLUMN(A1), 4),
    ω, FORMULATEXT(B$1),
    IF(AND(ISNUMBER(FIND(φ, ω)), 1 - ISNUMBER(FIND("""" & φ & """", ω))), A1, "")
)

Edit: that said, it would require a complex formula indeed to account for all potential false positives: I haven’t dealt with cases such as:

=MAX(Z1, AA1)

which would return a false positive for A1.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading