Goal Seek Macro w/ Variables

cdawg

New Member
Joined
Nov 19, 2009
Messages
5
Hello All,
I am having a bit of a problem with the syntax of a Goal Seek Command in a macro and would certainly appreciate any assistance. I have 30 cells which may trigger a goal seek if a certain value is above 0. The cells I am checking for the value > 0 are in D138 thru AE138. The goal and change value are relative to this item (within the same column - target is 8 rows below and change value is 6 rows above). My code is as follows:

Dim myRnge As Range

Set myRnge = Range("D130:AF130")
For Each cell In myRnge
If cell.Offset(8, 0) > 0 Then
cell.GoalSeek Goal:=cell.Offset(8, 0), ChangingCell:=cell.Offset(-6, 0)
End If
Next cell

When this macro is run, the message I receive is a "Run-Time Error 1004" Reference is not valid.

Thanks in advance for your help.

CDawg
 

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.
I think the problem is here. Of course its just a reference problem.
Rich (BB code):
cell.GoalSeek Goal:=cell.Offset(8, 0), ChangingCell:=cell.Offset(-6, 0)
I would see if the cell values are numbers and not text and see exactly where the reference is going. Of course in this scenerio the (-6,0) is actually wanting to change a cell that is part of the cell range with formulas. If I'm reading that right. You can't change a cell with a formula (I don't think you can). You need to reference a cell with no formula. (-6,0) would be referencing a cell with a formula. Or in other words a cell that is a variable.

Nicole
 
Last edited:
Upvote 0
Thanks for you input.

I do believe that the value of Cell within the range in my code is indeed a number. I think what I need is a range for the Goal Seek Function. I had to reset my changing value from a formula to a value. Then using the variables with the offsets worked.

Again, Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,631
Members
449,241
Latest member
NoniJ

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