A magic square needs no introduction and we come across it many times. A magic square is a square grid and the minimum size of a magic square is 3x3. The whole numbers in magic square appear only once and all cells are filled. The horizontal rows, vertical columns and main and secondary diagonals all add up to the same number. This number is called magic constant. The more about magic square can be read here - https://en.wikipedia.org/wiki/Magic_square

Below is a VBA code to construct a magic square for odd order i.e. you can create magic squares of size 3x3, 5x5, 7x7,9x9......

I have tested the magic square till 211x211....

The logic for creating an odd order magic square has been explained in the link given above. The logic has been coded in VBA. The macro will ask for what size of magic square is needed and it will create the magic square starting in cell B2 and will put thick border around the magic square created. I have code B2 as variables so that if anybody wants to change the starting cell, he can do that.

1. Make a backup of your workbook.
2. Open your workbook and ALT+F11
3. Locate your Workbook name in Project Explorer Window
4. Right click on your workbook name > Insert > Module
5. Copy paste the Macro code given
6. Go back to your Workbook and ALT+F8 to display Macro Window
7. Run your Macro named "MakeOddMagicSquare" from here
8. Delete you Macro if the Macro was needed to be run only once.
9. Otherwise save your file as .xlsm if you intend to reuse Macro again.