Vba help

prem

New member
Joined
Nov 5, 2024
Messages
3
Reaction score
0
Points
1
Excel Version(s)
windows
Want a Vba that allows user to highlight cells to form a table. Need exel to randomly assign '1' in empty cells in this table such that:
The sum of each row is equal to the value of the adjacent column after the table. AT THE SAME TIME.
The sum of each column of the table equals to the value of the adjacent row after the table.
 
To be more precise :

Row A contains names of invigilators this can vary in terms of numbers. Row 1 has the dates of exams, the number of exam can vary too. Hence the need for user to higlight cells to form the table.....in this case the table would start at B2 to L10.
In the table B2 to L10, some cells will contain 1 and some 0 and some blank.
I need a VBA that will randomly insert 1s in blank cells such that for e.g the sum of column B of the table must be equal to B11, which is fixed by me. While at the same time the sum of each row of the table is given by the cell value C18 in this case is 8.
Cell value in C18 will always be adjusted by me to ensure that it is possible to randomly assign 1 in the empty cells so that the sum of the row corresponds to value C18 and the sum of the column corresponds to row 11.
It will be great if the vba can also count the sum of the row and place it in the column adjacent to the table.....in this case Column M.

I tried several VBAs but can only manage to get it to randomly insert 1s and meet the sum of row or sum of column criteria but NOT BOTH. In the picture, this VBA inserted 1 randomly and was able to meet the criteria for the sum of each column.....but can't meet the criteria where the sum of the rows, in this case should be 8.

I hope some kind soul can help.
Picture4.jpg
Thanks.
 
Hi and welcome. Please post a sample sheet (no pics please), with some data and manually mocked-up results). Thx
 
Hi and welcome. Please post a sample sheet (no pics please), with some data and manually mocked-up results). Th
Hi.
Perhaps i should explain exactly what i am trying to do.
I am trying to create an exam invigilation schedule where each invigilator(A,B,C,D,E,F,G,H,J)gets the same number of invigilation..in this case 8. Row 11 shows how many invigilators i need each date(1,2,3,4,5,6,7,...11). The '0' that is preinserted in the table is to show that the invigilator is not free to invigilate and the preinserted '1' is to ensure that the invigilator is invigilating on the given date

Please see attached file. The problem is that the row sums should all be equal to 8!
Also the randomly assigned 1 should only be placed in empty cells while leaving non-empty cells alone...this too does not work.


Thanks for looking thru.
 

Attachments

  • Book2.xlsm
    23.4 KB · Views: 1
Last edited:
Back
Top