Return to VBA Code Examples

VBA – Using Goal Seek in VBA

This tutorial will show you how to use Goal Seek in VBA

Goal Seek is one of the What -if analysis tool available in Excel which allows you to apply different values to formulas and compare the results.

Goal Seek Syntax

vba goal seek syntax

The function GoalSeek has 2 arguments – the goal (the cell you want to change), and ChangingCell (the cell that needs to be amended).  The function returns a True or a False – True if the Goal is found, and False if the Goal is not found.

Using Goal Seek in VBA

Consider the following worksheet below.

vba goal seek example 1 before

To change the repayment required each month by changing the term in months, we can write the following procedure.

Note that there has to be a formula in cell B6, and a value in cell B5.

Using Goal Seek with an If Statement

You can also use GoalSeek with an If statement to direct the flow of your code.

vba goal seek if statement

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!