Gene banks are usually used for storing general genetic variability of endangered living populations but can be also used for storing alleles of a particular locus that are being eradicated through artificial selection programmes. In such scenarios gene banks would allow future re-introduction of one or more of the alleles being eradicated (and the associated diversity) into living populations. Frequencies within the bank for the locus of interest should have pre-determined target values. In this study, an algorithm is derived to obtain the optimal contributions of all candidate donors to achieve the target frequencies of the removed alleles in the bank while maintaining at the same time genetic variability in other loci unlinked to those targeted in the eradication programme. The efficiency of the algorithm is tested using the case of gene banks storing prion protein alleles currently disfavoured in scrapie eradication programmes (i.e., the AHQ, ARH, ARQ and VRQ alleles). Results showed that the algorithm was able to find the combinations of candidate contributions fulfilling different objectives regarding target frequencies and restrictions on coancestry. The most important factors influencing the optimal contributions were the allelic frequencies and the levels of diversity (coancestry) of the living population. Heterozygotes were favoured over homozygous individuals as, for a given number of animals contributing to the bank, the use of heterozygotes leads to lower levels of coancestry. Notwithstanding, almost all donors were sampled when restrictions on the global genetic diversity to be stored were severe.