Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Automating GoalSeek - why doesn't this code work?

I have a spreadsheet with calculations set up in columns.
I have used goal seek manually to get the answer I want
without incident. However, I want to find a way to do this
for each column as in one spreadsheet I have 67 columns to
check - a pain to do by hand.

I have come up with the following code that VBA/Excel does
not like. I would appreciate feedback, corrected code that
works and a explanation why it works!

Thanks,

Jeff

---

Sub GoalSeekReinforcement()
'Target cells start in column B
'Blank target cell indicates end of columns to be solved

Dim n As Integer

Dim tRange As Range
Dim sRange As Range
Dim tempRange1 As Range
Dim tempRange2 As Range
Dim Success As Boolean

'Target cell range - all are in row 166
Set tRange = ActiveSheet.Range("B166", Range("B166").End
(xlToRight))

'First change cell - all are in row 26'
Set sRange = ActiveSheet.Range("B26")

'Iterate over all columns that may need goal seek
For n = 1 To tRange.Columns.Count

'Put initial value in change cell as goal seek
requires a non-blank value to modify
sRange.Offset(0, n - 1).Cells(1, 1).Formula = "=8"

'Success is dummy boolean
Success = tRange.Offset(0, n - 1).Resize(1, 1).GoalSeek
(1, sRange.Offset(0, n - 1).Resize(1, 1))

Next n

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
Goalseek gives incorrect results dindigul New Users to Excel 1 July 12th 09 12:14 AM
Problem with Goalseek Macro Ken G.[_2_] Excel Discussion (Misc queries) 5 June 13th 09 01:16 PM
GoalSeek in VBA [email protected] Excel Discussion (Misc queries) 1 July 20th 06 05:13 AM
Automating data copying between work sheets Ian1 New Users to Excel 6 February 17th 06 02:41 PM
XL 2000: automating drag-and-drop for worksheet ranges. Using Code! Dan P Excel Programming 3 September 3rd 03 03:36 AM


All times are GMT +1. The time now is 08:29 PM.

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"