Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Multiple Goalseek - Range

Could anybody pls correct first part of macro macro below (problem
with defining the range- as i tried to modify an existing macro) -
Thxs

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

Let rgt = (Range("Column").Value)
Let Frz = 13 - (Range("Column").Value)
ActiveWorkbook.PrecisionAsDisplayed = False

Let Change = Range("Changedto").Offset(0, rgt).Resize(1, Frz)
Let Setc = Range("Setcell").Offset(0, rgt).Resize(1, Frz)
Let Bychg = Range("ByChanging").Offset(0, rgt).Resize(1, Frz)


restart:
With Application
Set TargetVal = Setc.Address

Set DesiredVal = Change.Address

Set ChangeVal = Bychg.Address

End With

'Ensure that the changing cell range contains only values, no
formulas allowed
Set CVcheck = Intersect(ChangeVal,
Union(Sheets(ChangeVal.Parent.Name).Cells.SpecialC ells(xlBlanks),
Sheets(ChangeVal.Parent.Name).Cells.SpecialCells(x lConstants)))
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
Using Excel Solver or Goalseek on multiple Sheets in a Workbook au AlfredR Excel Worksheet Functions 2 September 5th 07 10:06 AM
Nothing happens with range("B2").Goalseek _... Phil Excel Programming 1 February 27th 07 02:57 AM
GoalSeek in VBA [email protected] Excel Discussion (Misc queries) 1 July 20th 06 05:13 AM
mimic goalseek Monique Excel Programming 6 August 25th 05 07:11 PM
"GoalSeek method of Range object failed" error message Fixit_Steve Excel Programming 0 January 13th 05 07:29 PM


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