Skip to content

Instantly share code, notes, and snippets.

@excelcrafters
Created May 25, 2019 09:30
Show Gist options
  • Save excelcrafters/0aebaedd6dda67a3d61dd7f8cc47536d to your computer and use it in GitHub Desktop.
Save excelcrafters/0aebaedd6dda67a3d61dd7f8cc47536d to your computer and use it in GitHub Desktop.
Goal Seek analysis for multiple cells/range in Excel
Sub Goal_Seek_Range_SingleGoal()
'We are looping through each row in our table
For j = 5 To 13
'Below is how we replicate the Goal Seek functionality via VBA
'Cells(j, "F").GoalSeek - The cell that will hold our Goal value (in this case, Col F)
'Goal:=Cells(5, "H") - The value of our goal. In this case its referencing the value of Cell H5
'ChangingCell:=Cells(j, "E") - The input cell that needs to adjust its value inorder to achieve the goal
Cells(j, "F").GoalSeek Goal:=Cells(6, "H"), ChangingCell:=Cells(j, "E")
'Go to next iteration
Next j
End Sub
Sub Reset_External_Marks()
'Select the external marks range
Range("E5:E13").Select
'Clear the external marks range
Selection.ClearContents
End Sub
@excelcrafters
Copy link
Author

The XLSM file corresponding to this code is available at https://drive.google.com/open?id=1ufBkWspUdWrfFPHJ6cmvEBQ2LRmSqje6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment