Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
g-boy
 
Posts: n/a
Default Error Embedding Row() within Indirect()

I have a set of values in a range of cells on a worksheet, Patterns!B2:B375

There are also values in the corresponding cells in nearby columns,
such as Patterns!C2:C375, Patterns!D2:D375, Patterns!E2:E375, etc.

I want to calculate the correlations between the values in the first range,
and the values in each of the other columns. And I want these correlation
values to appear on different rows (for example, in place of the ### below):

Corrleation
ColC ###
ColD ###
ColE ###

And so, I thought I could use this function:

=CORREL(INDIRECT("Patterns!R2C"&(ROW()+1)&":R375C" &(ROW()+1),FALSE),Patterns!B$2:B$375)

in each of the cells, and it would automatically have each row calculate the
correlation with a different column of values.

But... it doesn't work. It gives me #N/A.

The TRULY STRANGE thing about this, is if I simply substitute the actual row
number in place of the ROW() function, it works:

=CORREL(INDIRECT("Patterns!R2C"&(2+1)&":R375C"&(2+ 1),FALSE),Patterns!B$2:B$375)

This actually produces the correct numerical result. And all I did, was
replace the embedded row() function call with an actual number.

Why should I not be able to embed row() within indirect()?

---G
  #2   Report Post  
Harlan Grove
 
Posts: n/a
Default

g-boy wrote...
....
And so, I thought I could use this function:

=CORREL(INDIRECT("Patterns!R2C"&(ROW()+1)&":R375C "&(ROW()+1),FALSE),Patterns!B$2:B$375)

in each of the cells, and it would automatically have each row

calculate the
correlation with a different column of values.

But... it doesn't work. It gives me #N/A.

....

The problem is that ROW() always returns an array, even when the array
only contains a single entry. INDIRECT accepts array first arguments
and then returns undocumented things that act as if they were arrays of
range references. Those can be used only as arguments in the few
functions that require range reference arguments. CORREL isn't one of
those functions, so you need to convert the array generated by ROW() to
a scalar. The simplest way to do that is SUM(ROW()). Yes, it looks odd,
but try it.

For that matter, you'd be better off using

=CORREL(OFFSET(Patterns!$A$2:$A$375,0,SUM(ROW())), Patterns!B$2:B$375)

  #3   Report Post  
g-boy
 
Posts: n/a
Default

[...]
The problem is that ROW() always returns an array, even when the array
only contains a single entry.


I didn't know that... I just assumed it returned the single (scalar) value
that was the row number of the cell in which the formula appears.

[...] For that matter, you'd be better off using

=CORREL(OFFSET(Patterns!$A$2:$A$375,0,SUM(ROW())), Patterns!B$2:B$375)


That's a great suggestion, thank you very much!!!

--G
  #4   Report Post  
Harlan Grove
 
Posts: n/a
Default

"g-boy" wrote...
....
The problem is that ROW() always returns an array, even when the array
only contains a single entry.


I didn't know that... I just assumed it returned the single (scalar) value
that was the row number of the cell in which the formula appears.

....

When formulas don't work when you change from a hardcoded value to a
function call, you should always try evaluating the particular function call
in the formula bar. If you type =ROW() in, say, X99 and press [F9], it
becomes ={99}.

This is just another of those things that you have to learn by experience
because online help for the ROW() function certainly doesn't mention this.
Indeed, I suspect ROW() [and COLUMN()] returning single entry arrays is a
bug, but Microsoft doesn't waste money fixing bugs that would affect only
the 10% or fewer of Excel users trying to do things like this.


  #5   Report Post  
Aladin Akyurek
 
Posts: n/a
Default

Harlan Grove wrote:
"g-boy" wrote...
...

The problem is that ROW() always returns an array, even when the array
only contains a single entry.


I didn't know that... I just assumed it returned the single (scalar) value
that was the row number of the cell in which the formula appears.


...

When formulas don't work when you change from a hardcoded value to a
function call, you should always try evaluating the particular function call
in the formula bar. If you type =ROW() in, say, X99 and press [F9], it
becomes ={99}.

This is just another of those things that you have to learn by experience
because online help for the ROW() function certainly doesn't mention this.
Indeed, I suspect ROW() [and COLUMN()] returning single entry arrays is a
bug, but Microsoft doesn't waste money fixing bugs that would affect only
the 10% or fewer of Excel users trying to do things like this.



Maybe

=ROW() in X99 == {99} instead of 99

because:

=ROW(X99:Z100) == {99,100}





  #6   Report Post  
Harlan Grove
 
Posts: n/a
Default

"Aladin Akyurek" wrote...
....
Maybe

=ROW() in X99 == {99} instead of 99

because:

=ROW(X99:Z100) == {99,100}


Maybe on your system, but on mine ROW(X99:Z100) returns {99;100}.

Maybe it's required for consistency. ROW() in a multiple cell array formula
does evaluate to a vertical array of the rows. Nevertheless, it'd be nice if
online help mentioned that it always returns arrays.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
referencing named formula using INDIRECT function [email protected] Excel Worksheet Functions 19 May 11th 05 09:48 AM
Sum Indirect function through multiple sheets Andre Croteau Excel Discussion (Misc queries) 2 May 6th 05 10:44 AM
Pivot ranges and INDIRECT daveydave60 Excel Worksheet Functions 1 April 22nd 05 12:15 PM
indirect formula Manos Excel Worksheet Functions 0 February 16th 05 01:17 PM
is there a NON-volatile version of INDIRECT ?? spiderman Excel Discussion (Misc queries) 1 February 4th 05 04:54 PM


All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"