Sets of integers that can be placed in a magic square

Yes, there is a formula for any $(n+1)\times (n+1)$ magic square, which can be deduced with a bit of hard work and clever moves:

Lets start

Because I do not have acces to editing tools, I will say thet cell $(a,b)$ is the cell on the $a^{th}$ line and $b^{tn}$ column.

Let us fill $(i,j)$ with $x_{(a-1)n+b}$, $\forall i,j$ with $1\leq i,j \leq n$ and $(n+1,n+1)=x$

Observe that the "magic sum" is $$\sum_{i=0}^{n-1}x_{in+i+1}+x=S$$

Rmember this property as $(*)$.

because those are the numbers on the big diagonal which starts at $(1,1)$ and ends at $(n+1,n+1)$

We can fill all the remaining cells accordingly.

We get that $\forall k$, $1\leq k\leq n$

$$(k,n+1)=S-\sum_{i=1}^{n}x_{(k-1)n+i}$$

and

$$(n+1,k)=S-\sum_{i=0}^{n-1}x_{in+k}$$

( Now, if you haven't done it already, draw this square. Maybe try for small cases like $n=4$ or $5$ first. )

For the square to be magical, we must check the property for the $(n+1)^{th}$ row, the $(n+1)^{th}$ column and the big diagonal that starts at $(1,n+1)$ and ends at $(n+1,1)$

In other words, the following must happen:

For the $(n+1)^{th}$ column:

$$S=\sum_{k=1}^{n}(k,n+1)+x=\sum_{k=1}^{n}\bigg(S-\sum_{i=0}^{n-1}x_{in+k}\bigg)+x=n\cdot S-\sum_{i=1}^{n^2}x_i+x$$

For the $(n+1)^{th}$ row:

$$S=\sum_{k=1}^{n}(n+1,k)+x=\sum_{k=1}^{n}\bigg(S-\sum_{i=1}^{n}x_{(k-1)n+i}\bigg)+x=n\cdot S-\sum_{i=1}^{n^2}x_i+x$$

For the second big diagonal:

$$S=\sum_{i=1}^{n+1}(i,n+2-1)=\bigg(S-\sum_{i=1}^{n}x_i\bigg)+\bigg(S-\sum_{i=0}^{n-1}x_{in+1}\bigg)+\sum_{i=2}^{n}x_{in-(i-2)}$$

The conditions for the $(n+1)^{th}$ column and row are the same. Using $(*)$, we get

$$x=\frac{\sum_{i=1}^{n^2}x_i-(n-1)\sum_{i=0}^{n-1}x_{in+i+1}}{n}$$

So this is the first condition. As an example, using the formula given in the comments for the $3\times 3$ square (so $n=2$), this is equivalent to:

$$c+b=\frac{\big(c-b+c+(a+b)+c-(a-b)+c\big)-\big(c-b+c\big)}{2}=\frac{2c+2b}{2}$$

which is true.

Now lets see the condition for the other big diagonal. We have

$$S=\sum_{i=1}^{n+1}(i,n+2-1)=\bigg(S-\sum_{i=1}^{n}x_i\bigg)+\bigg(S-\sum_{i=0}^{n-1}x_{in+1}\bigg)+\sum_{i=2}^{n}x_{in-(i-2)}$$

so by using $(*)$ and reducing, we get

$$x=\sum_{i=1}^{n}x_i+\sum_{i=0}^{n-1}x_{in+1}-\sum_{i=2}^{n}x_{in-(i-2)}-\sum_{i=0}^{n-1}x_{in+i+1}$$ 9again, this can be checked using the formula for $3\times 3$)

To conclude

The only condition (sufficient and necessary) for a square to be perfect is: (note, I got the final result by using the 2 equalities for $x$ and by reducing some terms)

Consider an $(n+1)\times(n+1)$ square. Consider $(a,b)$ the cell situated on the $a^{th}$ line and $b^{tn}$ column. Let us fill $(i,j)$ with $x_{(a-1)n+b}$, $\forall i,j$ with $1\leq i,j \leq n$. Then, we must have: $$\sum_{i=1}^{n^2}x_i+\sum_{i=0}^{n-1}x_{in+i+1}=n\cdot\bigg(\sum_{i=1}^{n}x_i+\sum_{i=0}^{n-1}x_{in+1}-\sum_{i=2}^{n}x_{in-(i-2)}\bigg)$$

So to answer your questions:

Given a set of $(n+1)^2$ integers, we can form an $(n+1)\times (n+1)$ perfect square with them if and only if there exist $x_1,x_2,...,x_{n^2}$ such that $$\sum_{i=1}^{n^2}x_i+\sum_{i=0}^{n-1}x_{in+i+1}=n\cdot\bigg(\sum_{i=1}^{n}x_i+\sum_{i=0}^{n-1}x_{in+1}-\sum_{i=2}^{n}x_{in-(i-2)}\bigg)$$

Finishing touches

To get the actual formula for every single damn cell, just use whichever formula for $(n+1,n+1)=x$ you want, and then the formulas for $(n+1,k$ and $k,n+1)$

P.S. I am sorry, but the formulas cannot get nicer than this :(