VBA Help Goal Seek with dynamic cell

smittymj

New Member
Joined
Jun 12, 2018
Messages
26
Good day all! I'm trying to make a goal seek function but the change cell target is dynamic based on a certain cell. Hoping to have some help or improvements on the below. Thank you!

Sub GoalSeek()

Dim Answer As Integer

Answer = MsgBox("Run values?", vbYesNo + vbQuestion)

If Answer = vbYes Then

Range("E37").GoalSeek _
Goal:=0, _
ChangingCell:=Range("One cell between I66 - R66 depending on number in cell F5")

ElseIf Answer = vbNo Then
MsgBox "Cancelled", vbExclamation
End If

End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Range("One cell between I66 - R66 depending on number in cell F5")

What is the relationship of the number in cell F5 to the dynamic cell.
That is, to select cell I66, what number do you have in cell F5. If in cell F5 you have what number then the cell will be J66, If in cell F5 you have what number then the cell will be K66, etc?

Could you explain it with examples?
🧙‍♂️
 
Upvote 0
What is the relationship of the number in cell F5 to the dynamic cell.
That is, to select cell I66, what number do you have in cell F5. If in cell F5 you have what number then the cell will be J66, If in cell F5 you have what number then the cell will be K66, etc?

Could you explain it with examples?
🧙‍♂️
Hi thank you for replying! F5 is sort of a scenario selector (Numbers 1 to 5 for example). So if it's 1, the cell to change is I66, 2 is J66 and so on. Sorry for the confusion!
 
Upvote 0
Try:

VBA Code:
Sub GoalSeek()
  Dim Answer As Integer
  
  Answer = MsgBox("Run values?", vbYesNo + vbQuestion)
  If Answer = vbYes Then
    Range("E37").GoalSeek _
      Goal:=0, _
      ChangingCell:=Range("I66").Offset(0, Range("F5").Value - 1)
  ElseIf Answer = vbNo Then
    MsgBox "Cancelled", vbExclamation
  End If
End Sub
 
Upvote 1
Solution
Try:

VBA Code:
Sub GoalSeek()
  Dim Answer As Integer
 
  Answer = MsgBox("Run values?", vbYesNo + vbQuestion)
  If Answer = vbYes Then
    Range("E37").GoalSeek _
      Goal:=0, _
      ChangingCell:=Range("I66").Offset(0, Range("F5").Value - 1)
  ElseIf Answer = vbNo Then
    MsgBox "Cancelled", vbExclamation
  End If
End Sub
Thank you so much! I also realized that the cell to change is in another sheet. I tried using the line below (bold is code added) but it didnt seem to work:

ChangingCell:=Worksheets("Assumptions").Range("I66").Offset(0, Range("F5").Value - 1)

Hoping it's not too much trouble.
 
Upvote 0

Forum statistics

Threads
1,224,890
Messages
6,181,612
Members
453,057
Latest member
LE102024

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