Find the Smallest Value That Makes an Excel Test TRUE
Question details
Find the smallest input value that causes a dependent spreadsheet formula or logical test to return TRUE.

- Product
- Microsoft Excel VBA and WPS Spreadsheet macros
- Device & OS
- not provided
- Scenario
- A single input cell controls a formula or test cell, and the user needs to automate a search for the first successful value.
- Observed behavior
- The desired result is to leave the smallest value that makes the dependent test evaluate to TRUE in the input cell.
Identify the input cell and the dependent test cell before running a macro. Confirm that increasing the input value can eventually make the test return TRUE, and choose a realistic maximum value or iteration limit.
Use a bounded VBA loop to find the first TRUE result
Use this method when a TRUE/FALSE formula cannot be expressed as a numeric Goal Seek target and one input cell is tested in increasing increments.
The macro starts at a specified value, writes each candidate value to the input cell, recalculates the sheet, and stops at the first TRUE result. A maximum limit prevents the macro from running indefinitely when no matching value exists.
Press Alt+F11 in Excel, select Insert > Module, and replace "A1" with the input cell and "B1" with the cell that contains the TRUE/FALSE test.
Paste this macro into the module: Sub FindSmallestTrue()\n Dim ws As Worksheet\n Dim candidate As Long\n Dim maxValue As Long\n\n Set ws = ActiveSheet\n candidate = 0\n maxValue = 100000\n\n Do While candidate <= maxValue\n ws.Range("A1").Value = candidate\n ws.Calculate\n If ws.Range("B1").Value = True Then\n MsgBox "Smallest value: " & candidate\n Exit Sub\n End If\n candidate = candidate + 1\n Loop\n\n MsgBox "No TRUE result was found up to " & maxValue\nEnd Sub
In the VBA editor, change candidate = 0 to the lowest value you want to test and change maxValue = 100000 to the highest permitted value. Change candidate = candidate + 1 if the search must use a different increment.
Place the cursor inside FindSmallestTrue and press F5, or return to the workbook and choose Developer > Macros > FindSmallestTrue > Run. The input cell remains set to the first value that returns TRUE.

Use Goal Seek when the test can be converted to a numeric target
Use Goal Seek for a single formula that can return a numeric threshold, such as 1 for success and 0 for failure.
Search for the first TRUE value with WPS Spreadsheet
WPS Spreadsheet provides a familiar worksheet environment for building dependent formulas and running compatible macro workflows. You can test incremental values with a bounded macro or use Goal Seek when your logical result can be represented by a numeric helper formula.
- 1. Open the workbook in WPS Spreadsheet: Launch WPS Office, select Spreadsheets, and open the Excel workbook containing the input cell and dependent test formula.
- 2. Check the logical test: Select the test cell and confirm that its formula returns TRUE or FALSE as the input cell changes.
- 3. Add a bounded macro search: Open the macro editor from the Developer tools, insert a module, and add a loop that updates the input cell, recalculates the sheet, and stops when the test is TRUE.
- 4. Run and verify the result: Run the macro from the Macros command, then confirm that the value left in the input cell is the first successful value within the selected range.

Frequently Asked Questions
Can Excel Goal Seek target a TRUE or FALSE cell directly?
No. Goal Seek expects a numeric target. Create a helper cell such as =--B1 to convert the Boolean result in B1 into 1 for TRUE and 0 for FALSE, then target 1.
How do I make the VBA macro search values other than whole numbers?
Change the increment line from candidate = candidate + 1 to a smaller step, such as candidate = candidate + 0.01, and declare candidate as Double instead of Long.
Why does the macro need a maximum iteration or maximum value?
A limit prevents an endless loop when no tested value makes the formula return TRUE. Set the limit to the highest value that is meaningful for your worksheet.
Will the loop always find the mathematical smallest value?
It finds the first value in the order and increment you specify. For example, a loop starting at 0 and increasing by 1 finds the smallest nonnegative whole-number result, not values between integers.
What should I do if the test cell contains an error instead of TRUE or FALSE?
Correct the formula error first, or add error handling to the macro. Check that cell references, input types, and dependent formulas calculate correctly before running the search.




