There are a couple of ways to try this problem . . .
1. The way you probably have been trying is guess and check: P is probably a 7 since it is shared by the 4 largest numbers etc.
2. Setting up simultaneous equations with all 40 variables. You would need 40 equations to solve it easily but I can only see the following:
4 vertical rows that add up to the sum of (1 through 7)
4 horizontal rows that add up to the sum of (1 through 7)
9 sum of 8 variables that are surronding grey squares.
so you have 17 equations and 40 unknowns.
I think a combination of the two strategies will help you out. for example set up the equations and make some intelligent guesses and see where it takes you.