Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default Vertical Multiple Goal Seek

Can someone correct the macro below to make it work when the data are
aligned vertically instead of horizontal (presently only 1st cell is
getting right goal seek value - other cells below are not properly
updated)

Sub Multi_Goal_Seek()
Dim TargetVal As Range, DesiredVal As Range, ChangeVal As Range,
CVcheck As Range
Dim CheckLen As Long, i As Long

restart:
With Application
Set TargetVal = .InputBox(Title:="Select a range in a single
row or column", _
Prompt:="Select your range which contains the ""SET CELL""
range", Type:=8)
'no default option
'prompt:="Select your range which contains the ""Set Cell""
range",, Type:=8)
Set DesiredVal = .InputBox(Title:="Select a range in a single
row or column", _
Prompt:="Select the range which the ""Set Cells"" will be
changed to - TO VALUE", Type:=8)
'no default option
'prompt:="Select the range which the ""Set Cells"" will be
changed to",, Type:=8)
Set ChangeVal = .InputBox(Title:="Select a range in a single
row or column", _
Prompt:="Select the range of cells that will be changed - BY
CHANGING", Type:=8)
'no default option
'prompt:="Select the range of cells that will be changed",,
Type:=8)
End With

'Ensure that the changing cell range contains only values, no
formulas allowed
Set CVcheck = Intersect(ChangeVal, Union(Sheets
(ChangeVal.Parent.Name).Cells.SpecialCells(xlBlank s), Sheets
(ChangeVal.Parent.Name).Cells.SpecialCells(xlConst ants)))
If CVcheck Is Nothing Then
MsgBox "Changing value range contains no blank cells or
values" & vbNewLine & _
"Goal seek only works if the cells to be changed are values,
please ensure that this is the case", vbCritical
Application.Goto Reference:=DesiredVal
Exit Sub
Else

If CVcheck.Cells.Count < DesiredVal.Cells.Count Then
MsgBox "Changing value range contains formulas" &
vbNewLine & _
"Goal seek only works if the cells to be changed are
values, please ensure that this is the case", vbCritical
Application.Goto Reference:=DesiredVal
Exit Sub
End If
End If

'Ensure that the amount of cells is consistent
If TargetVal.Cells.Count < DesiredVal.Cells.Count Or
TargetVal.Cells.Count < ChangeVal.Cells.Count Then
CheckLen = MsgBox("Ranges were different lengths, please press
yes to re-enter", vbYesNo + vbCritical)
If CheckLen = vbYes Then
'If ranges are different sizes and user wants to redo
then restart code
GoTo restart
Else
Exit Sub
End If
End If

' Loop through the goalseek method
For i = 1 To TargetVal.Columns.Count
TargetVal.Cells(i).GoalSeek Goal:=DesiredVal.Cells(i).Value,
ChangingCell:=ChangeVal.Cells(i)
Next i
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
Multiple Goal Seek Ivanl Excel Programming 0 January 28th 08 07:28 PM
goal seek multiple cells massimo Excel Worksheet Functions 2 November 9th 07 04:02 PM
how to use goal seek in multiple cells? A.M.Vel Excel Discussion (Misc queries) 0 July 27th 06 01:26 PM
Goal seek multiple cells ?? Excel Worksheet Functions 1 August 5th 05 07:32 AM
Goal Seek on Multiple Cells newtoloop Excel Worksheet Functions 0 February 17th 05 10:01 PM


All times are GMT +1. The time now is 09:09 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"