У меня получилось 6216
Dim i As Integer
Dim s As Integer
Dim d As Integer
For i = 1000 To 9999
s = CInt((CInt(Mid(CStr(i), 1, 1))) ^ 2 + (CInt(Mid(CStr(i), 2, 1))) ^ 2 + (CInt(Mid(CStr(i), 3, 1))) ^ 2 + (CInt(Mid(CStr(i), 4, 1))) ^ 2)
If s Mod 2 = 0 Or s Mod 3 = 0 Then d += 1
Next
MsgBox(d)