Function fact(n As Integer) As Long
Dim i As Integer, p As Long
p = 1
For i = 2 To n
p = p * i
Next i
fact = p
End Function
Sub Test()
Dim n As Integer, s As Long, i As Integer
s = 0
n = CInt(InputBox("Введите число n"))
For i = 1 To n
s = s + fact(i)
Next i
MsgBox s
End Sub