A
al
How can i goal seek on several sheets from 1 macro - pls correct macro
below which is not doing the work thxs
Sub Goalseekall()
Dim WS As Worksheet
Dim MinIndex As Long
Dim MaxIndex As Long
Dim RngToCopy As Range
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = False 'Prevents the user from seeing
the screen
MinIndex = Worksheets("Pivot").Index
MaxIndex = Worksheets("End").Index
If MinIndex > MaxIndex Then
'swap them
MinIndex = MaxIndex
MaxIndex = Worksheets("Pivot").Index
End If
For Each WS In ActiveWorkbook.Worksheets
With WS
If .Index > MinIndex _
And .Index < MaxIndex Then
'do the work
Range("Y84").Goalseek Goal:=Range("AL84"), ChangingCell:=Range("Y50")
Range("Y85").Select
Range("Y85").Goalseek Goal:=Range("AL85"), ChangingCell:=Range("Y51")
Range("Y86").Select
Range("Y86").Goalseek Goal:=Range("AL86"), ChangingCell:=Range("Y52")
End If
End With
Next WS
End Sub
below which is not doing the work thxs
Sub Goalseekall()
Dim WS As Worksheet
Dim MinIndex As Long
Dim MaxIndex As Long
Dim RngToCopy As Range
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = False 'Prevents the user from seeing
the screen
MinIndex = Worksheets("Pivot").Index
MaxIndex = Worksheets("End").Index
If MinIndex > MaxIndex Then
'swap them
MinIndex = MaxIndex
MaxIndex = Worksheets("Pivot").Index
End If
For Each WS In ActiveWorkbook.Worksheets
With WS
If .Index > MinIndex _
And .Index < MaxIndex Then
'do the work
Range("Y84").Goalseek Goal:=Range("AL84"), ChangingCell:=Range("Y50")
Range("Y85").Select
Range("Y85").Goalseek Goal:=Range("AL85"), ChangingCell:=Range("Y51")
Range("Y86").Select
Range("Y86").Goalseek Goal:=Range("AL86"), ChangingCell:=Range("Y52")
End If
End With
Next WS
End Sub