Is it possible to program Excel to automatically change the inputs based on a rule set until a certain objective is met? For instance, I have a spreadsheet that automatically tests the (statistical) probability of risk and return of a certain portfolio by changing the inputs (assets). Would it be possible to have a macro (or something) to systematically test all possibilities within a certain rule set, stopping when a certain goal is met?

It's nothing a bunch of nested for loops couldn't do if I modeled the spreadsheet into a programming language I am familiar with. But I'd like to save some time if possible.