vendredi 22 avril 2016

VBA: adding random numbers to a grid that arent already in the grid

enter image description hereI am trying to do a part of a homework question that asks to fill in missing spaces in a magic square in VBA. It is set up as a (n x n) matrix with n^2 numbers in; the spaces I need to fill are represented by zeros in the matrix. So far I have some code that goes through checking each individual cell value, and will leave the values alone if not 0, and if the value is 0, it replaces them with a random number between 1 and n^2. The issue is that obviously im getting some duplicate values, which isn't allowed, there must be only 1 of each number.

How do I code it so that there will be no duplicate numbers appearing in the grid? I am attempting to put in a check function to see if they are already in the grid but am not sure how to do it

Thanks




Aucun commentaire:

Enregistrer un commentaire