Use the formula 2n2 where n is the no. of the shell K,L,M etc. this formula is used to find no. of electrons that can be accommodated in a shell
For ex, if you want valency of element with atomic no.34
Then using the formula
For 1st shell 2×1×1=2
For 2nd shell 2×2×2=8
For 3rd shell 2×3×3=18
Here's the trick adding the electrons in these shells.=28 And the no. left is 6
So as we know we need 8 electrons in last shell so, 2 electrons are less so the valency is -2
If the atomic no.were 36 it would be a noble gas valency = 0, 37 then a valency = +1