Excel Solver is a free add-in that's available natively within Excel.
Microsoft provides an overview of defining and solving an optimization problem using the Solver add-in:
Solver is a Microsoft Excel add-in program you can use for what-if analysis. Use Solver to find an optimal (maximum or minimum) value for a formula in one cell – called the objective cell – subject to constraints, or limits, on the values of other formula cells on a worksheet.
Solver works with a group of cells, called decision variables or simply variable cells that are used in computing the formulas in the objective and constraint cells. Solver adjusts the values in the decision variable cells to satisfy the limits on constraint cells and produce the result you want for the objective cell.
Microsoft. "Define and solve a problem by using Solver"
For more information: Define and solve a problem by using Solver