Google Sheets – Fix ‘Parameter X Value Y is Out of Range’ Error

google sheets

I'm making a random team selector but I'm getting a #NUM! error saying that "Parameter 2 Value 20" or "Parameter 2 Value 25" is out of range. From what I understand, they are not.

The parameters referred by the function are in other sheets.. Here is the link to it. Example:

Various football club emblems

Do you think this is a bug or am I doing something wrong?

Best Answer

I see commands like

=index(Spain!A$2:A$19, randbetween(2,19))

The second parameter of index is not the absolute row number but is relative to the range specified as the first argument. For example,

  • =index(A$2:A$19, 1) refers to A2
  • =index(A$2:A$19, 18) refers to A19
  • =index(A$2:A$19, 19) throws an error

To fix this, either change the range of randbetween:

=index(Spain!A$2:A$19, randbetween(1,18))

or, if you want to refer by absolute row numbers, use indirect:

=indirect("Spain!A"&randbetween(2,19))