Zend certified PHP/Magento developer

Replacing numbers in a row with another number from another column if the numbers are lower than 1000

I need to substitute numbers in a row if they are lower than 1000 with the mean of numbers in that row calculated without inclusion of the numbers in the row that are lower than 1000.

I’ve successfully calculated the mean using this code “=AVERAGE(IF(O3:V3>=1000, O3:V3))”, however when I try to substitute the numbers that are lower than 1000 with the calculated mean, I receive #spill error. This is the code I’m using: =IF(O3:V3<1000, W3, O3:V3). Mean values are located in column “W”.