Pestomania
Active Member
- Joined
- May 30, 2018
- Messages
- 330
- Office Version
- 365
- Platform
- Windows
Hi all,
I am running the following "Goal Seek" on loop through all sheets. If it is sheet by sheet (without loop), everything works. But when I place it on loop, the "Annual_Runs" fails. Can anyone help?
I am running the following "Goal Seek" on loop through all sheets. If it is sheet by sheet (without loop), everything works. But when I place it on loop, the "Annual_Runs" fails. Can anyone help?
VBA Code:
Sub Goal_Seek()
Dim ws As Worksheet
ActiveWorkbook.Worksheets(1).Activate
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "*- Greenfield" Then
ws.Activate
Application.ScreenUpdating = True
Dim Utilization As String
Dim Utilization_Address As String
Dim Target As String
Dim Equipment As Range
Dim Equipment_Address As String
Dim Annual_Runs As Range
Dim Urng As Range
Dim t As Integer
Application.ScreenUpdating = False
Range("D32").Select
Set Urng = Range(ActiveCell, ActiveCell.End(xlDown))
t = WorksheetFunction.CountA(Urng)
i = 0
Do Until i = t
Utilization_Address = ActiveCell.Address
Target = ActiveCell.Offset(0, 1)
Set Equipment = ActiveCell.Offset(0, 2)
Equipment_Address = ActiveCell.Offset(0, 2).Address
Set Annual_Runs = ActiveCell.Offset(0, -1)
Equipment.Value = 1
If Annual_Runs = 0 Then
Equipment.Value = 0
Else
Range(Utilization_Address).GoalSeek Goal:=Target, ChangingCell:=Equipment
End If
ActiveCell.Offset(1, 0).Select
i = i + 1
Loop
End If
Next ws
Application.ScreenUpdating = True
End Sub