You need to use an IF statement as part of your formula to check if the value in column D is blank
The below would be the formula to be added into column H. The if(D2=closed, "" is checking if D2 equals Closed and if it does, is entering a blank value.
=IF(D2="Closed","",(TODAY()-G2)&" "&"Days")