Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Goal Seek with dynamic Goal Seek

The below is to handle a Goal Seek in which the "Set Cell" and "To Value" can
vary. No matter what I do to this, I keep getting shot down with Reference
not valid..

Recording a macro gives me:
Sheets("Calcs").Range("L22").GoalSeek Goal:=558226, ChangingCell:=Range( _
"B42")

What changes in the above is to determine the cell on the "Calcs" that has
the target value and to what value.


Sub GoalSeekCSVR1C1()
'
' GoalSeekCSV Macro
'
Set wb = ThisWorkbook
Set wsGUI = wb.Worksheets("GUI")
Set wsCalcs = wb.Worksheets("Calcs")
intTargetCellRow = wsGUI.Range("TargetCellRow")
intTargetCellCol = wsGUI.Range("TargetCellCol")
wsGUI.Activate

varGoal = wsGUI.Range("TargetAmount").Value
strChangeRange = wsGUI.Range("B42").Address
wsCalcs.Cells(intTargetCellRow, intTargetCellCol).GoalSeek
Goal:=varGoal, ChangingCell:=strChangeRange

Set wsGUI = Nothing
Set wsCalcs = Nothing
Set wb = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Goal Seek with dynamic Goal Seek

I solved my own problem.

"Dkline" wrote:

The below is to handle a Goal Seek in which the "Set Cell" and "To Value" can
vary. No matter what I do to this, I keep getting shot down with Reference
not valid..

Recording a macro gives me:
Sheets("Calcs").Range("L22").GoalSeek Goal:=558226, ChangingCell:=Range( _
"B42")

What changes in the above is to determine the cell on the "Calcs" that has
the target value and to what value.


Sub GoalSeekCSVR1C1()
'
' GoalSeekCSV Macro
'
Set wb = ThisWorkbook
Set wsGUI = wb.Worksheets("GUI")
Set wsCalcs = wb.Worksheets("Calcs")
intTargetCellRow = wsGUI.Range("TargetCellRow")
intTargetCellCol = wsGUI.Range("TargetCellCol")
wsGUI.Activate

varGoal = wsGUI.Range("TargetAmount").Value
strChangeRange = wsGUI.Range("B42").Address
wsCalcs.Cells(intTargetCellRow, intTargetCellCol).GoalSeek
Goal:=varGoal, ChangingCell:=strChangeRange

Set wsGUI = Nothing
Set wsCalcs = Nothing
Set wb = Nothing
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Goal Seek Sandra P Excel Worksheet Functions 1 February 18th 09 03:54 PM
Goal Seek Tarig Excel Discussion (Misc queries) 3 February 23rd 08 10:24 PM
vba goal seek 2 csw78[_3_] Excel Programming 1 June 12th 05 08:24 PM
Goal Seek Jake Excel Discussion (Misc queries) 1 June 12th 05 05:55 AM
Goal Seek Tiya Excel Worksheet Functions 1 May 11th 05 12:38 PM


All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"