Excel only stores 15 significant figures for numbers. Any figures beyond that automatically get rounded, regardless of number format.
Setting the cell to Text format first will store the number as a string with as many digits as you want, but Excel can't perform any calculations on it.
However, VBA can do calculations with Decimal type variables which can store up to 29 significant figures.
If you first store the values as text in Excel (setting the cell number format to Text before entering the values), you can create a User Defined Function in VBA to read the string values, convert them to Decimal values, perform your calculations and then return a string with the full precision calculated.
For example:
Function PrecisionSum(ra As Range) As String
'Declare variables holding high precision Decimal values as Variants
Dim decSum As Variant
'This loop will sum values from all cells in input range
For Each raCell In ra
'Read values from input cells, converting the strings to Decimals using CDec function
decSum = decSum + CDec(raCell.Value)
Next raCell
'Return calculated result as a String
PrecisionSum = Format(decSum, "0.00000000000000000000")
End Function
You'll need to write functions to do the operations that you desire.
Note that you'll still be limited by the accuracy of any functions you use in VBA. For example, the SQR function to return the square root of a number only returns a number with Double precision regardless of the precision of the input.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…