Goal Seek Loop

Ottsel

Board Regular
Joined
Jun 4, 2022
Messages
174
Office Version
  1. 365
Platform
  1. Windows
Trying to construct a loop that'll use the Goal Seek function within excel. Instead of doing one at a time I'm attempting to do 10 at a time within a for loop.

Here's what I have so far, but I'm unsure where my error is:
VBA Code:
Sub NewAdjustments()

Dim CellChng As Integer
Dim i As Integer

    CellChng = InputBox("Please input the desired adjustment.")
            If CellChng = "" Then
            Exit Sub
    End If

    Application.CutCopyMode = False

    '...Plan 1
    For i = 12 To 20
        Range("AR & i").GoalSeek Goal:=CellChng, ChangingCell:=Range("AC & i")
    Next i
   
End Sub

Description:
AC12:AC20 have amounts that need to change.
AR12:AR20 have current percentages. These change depending on what is within the AC column
Inputbox is where I enter my changing amount.

Example:
Range.AR12 = -14.2%
I wish to change this to -8%
Range.AC12 = 1,200

Now, entering -8% will change Range.AC12 to 2,386

My goal is to find the value for all 10 rows to see what the amounts will be at -8% or any amount for that matter.

Also, formulas do not work here, thus VBA is required or the GoalSeek Function within the Data Tab.

Any help, tips or tricks would be greatly appreciated - thank you!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Trying to construct a loop that'll use the Goal Seek function within excel. Instead of doing one at a time I'm attempting to do 10 at a time within a for loop.

Here's what I have so far, but I'm unsure where my error is:
VBA Code:
Sub NewAdjustments()

Dim CellChng As Integer
Dim i As Integer

    CellChng = InputBox("Please input the desired adjustment.")
            If CellChng = "" Then
            Exit Sub
    End If

    Application.CutCopyMode = False

    '...Plan 1
    For i = 12 To 20
        Range("AR & i").GoalSeek Goal:=CellChng, ChangingCell:=Range("AC & i")
    Next i
  
End Sub

Description:
AC12:AC20 have amounts that need to change.
AR12:AR20 have current percentages. These change depending on what is within the AC column
Inputbox is where I enter my changing amount.

Example:
Range.AR12 = -14.2%
I wish to change this to -8%
Range.AC12 = 1,200

Now, entering -8% will change Range.AC12 to 2,386

My goal is to find the value for all 10 rows to see what the amounts will be at -8% or any amount for that matter.

Also, formulas do not work here, thus VBA is required or the GoalSeek Function within the Data Tab.

Any help, tips or tricks would be greatly appreciated - thank you!

Well, appears after reviewing and looking up my structure I found my issue. Apologies, but if anyone wants to add any extras or tips and tricks those are always welcomed.

VBA Code:
Range("AR" & i).GoalSeek Goal:=CellChng, ChangingCell:=Range("AC" & i)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top