Offset and goalseek

RussHatt

New Member
Joined
Nov 13, 2019
Messages
2
hi, I am struggling to get an offset to work on a goal seek i am trying to do. Essentially i want to goal seek a value in row1, column1 to zero by changing the value of the cell in row 3, column 1. In the next round of calculations, ie when i apply the offset, I want to goalseek row1, column2 to zero by changing the cell in row 3, column 2. Sounds simple but i am doing something wrong. the first calculation works but as soon as i calculate the next column then it breaks down... any ideas...

Code:
Sub MySteppedGoalSeek()

Dim ValueAtPt1 As Range
Dim ValueAtPt2 As Range
Dim counter As Integer


counter = 1
Do
Set ValueAtPt1 = Range("D27").Offset(0, counter)
Set ValueAtPt2 = Range("D31").Offset(0, counter)
ValueAtPt1.GoalSeek goal:=0, changingcell:=ValueAtPt2
counter = counter + 1
Loop Until counter = 10


End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Welcome to the Forum.

As written, your code will try to vary E31 to get E27 = 0, F27 to get F31 to 0, ... M31 to get M27 to 0.

I'm not sure how this fits with your description of Row 1 and Row 3, nor what you mean by "breaks down"?
 
Upvote 0
hi, I am struggling to get an offset to work on a goal seek i am trying to do. Essentially i want to goal seek a value in row1, column1 to zero by changing the value of the cell in row 3, column 1. In the next round of calculations, ie when i apply the offset, I want to goalseek row1, column2 to zero by changing the cell in row 3, column 2. Sounds simple but i am doing something wrong. the first calculation works but as soon as i calculate the next column then it breaks down... any ideas...

Code:
Sub MySteppedGoalSeek()

Dim ValueAtPt1 As Range
Dim ValueAtPt2 As Range
Dim counter As Integer


counter = 0
Do
Set ValueAtPt1 = Range("D27").Offset(0, counter)
Set ValueAtPt2 = Range("D31").Offset(0, counter)
ValueAtPt1.GoalSeek goal:=0, changingcell:=ValueAtPt2
counter = counter + 1
Loop Until counter = 10


End Sub

Thanks for answering Stephen. I found the issue! Your description of what it should do, is what i wanted it to do. The rows and cols was supposed to make it easier to understand. Fail on my part. The real issue turns out that i had a formula in the ValueAtPt2 row. Excel didnt warn me of my stupidity but rather just returns a reference error 1004. I changed the formula to a number and it now work. Thanks for the help!
 
Upvote 0
Great, I'm glad you figured it out.

If you use the Forum again, the more explicit you can be about your problem, the better.

It breaks down doesn't convey a lot of information.

But Run-time error 1004: Reference isn't valid would immediately suggest there is a formula, rather than a value, in the ChangingCell.
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,972
Members
452,540
Latest member
haasro02

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