Place your cursor in the cell with the formula, turn on the macro recorder, press F2 and then press tab. Now turn off the macro recorder. Open up the VBE and the code will be there.
Or simply, copy and paste (Note: I also adjusted your formula a tad)
Code:
Sub MyFormula()
Range("D1").Formula = "=IF('8'!D17<>"""",'8'!D17,""NO TEAM"")"
End Sub
Notice, anytime you have quotes in VBA they need to be doubled up.
Also, the first method will record the formula in R1C1 notation.