I need a formula to test a single cell to find the greatest whole number divisor of the value in the cell. The value in the cell being tested will not be a negative, fraction or any sort of decimal. My attempts so far have failed. I am using LibreOffice Calc in Linux Mint.
Example:
Row 1 - if the cell contains 4 the result is 2
Row 2 - if the cell contains 21 the result is 7
Row 3 - if the cell contains 23 the result is -1
Row 4 - if the cell contains 51 the result is 17
and so on
=IF(RC[-1]>0,MAX(IF(MOD(R[1]C[1],ROW(INDIRECT(ā1:ā&RC[-1])))=0,ROW(INDIRECT(ā1:ā&RC[-1])),-1)),"")
RC[-1] contains the value I want to find the greatest divisor of. Iāve tried to make the formula generate numbers from 1 to the value in RC[-1] using the ROW and INDIRECT functions. Then test result for divisibility using the MOD function. If a number is a divisor of RC[-1], I thought the ROW/INDIRECT functions would return the number, or otherwise -1. The MAX function would then return the maximum divisor from possible divisors.
How ever I cannot get it to work. I get #REF!. I have tried a number of things, believing that I have the context or syntax wrong -but to no avail.
It has occurred to me that I am trying to use the wrong functions, I have tried GCD but got nowhere.
Please note I am avoiding anything that uses ārangesā of numbers.
Regards Andy