Sorry, now I'm totally mystified.
Firstly, it sounds as though you are expecting to have a formula that
actually reads D38 = (B29*((B31-G34))**2)/2
Excel formulas do not have anything to the left of the equals sign. So, in
cell D38 you could have a formula =(B29*((B31-G34))**2)/2.
Well, you couldn't really, because ** is not an Excel operator. But you
could have =(B29*((B31-G34))*2)/2
Now that calculates a value to go into the cell it's in, which might be D38,
or wherever you've put it.
What is an "If then loop"? An "If then" is a statement; a "loop" is an
entirely different statement. Additionally, Excel formulas do not have
loops; and they don't strictly have "If then", although they do have calls
to an IF function.
And what does "If range("D38").value <> 0 then ?" mean? For starters, that
is not a formula, it is part of a VBA statement.
As I indicated earlier, if you want to use a formula like the above to
produce a value of zero, then one side or other of the first multiplication
operator must be zero. This is Algebra, not Excel.