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 Loop several sheets - part 4 - Dave Peterson - Goal seek

why do i have to start running this macro in a sheet in which AL54
has a value & not any other sheet outside selected "range" sheets??
Would prefer it to work when any sheet is active - thxs



Sub Goalseekoffsetall()

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


..Cells(84, Range("AL54").Value + 4).Goalseek Goal:=.Range("AL84"),
ChangingCell:=.Cells(50, Range("AL54").Value + 4)

..Cells(85, Range("AL54").Value + 4).Goalseek Goal:=.Range("AL85"),
ChangingCell:=.Cells(51, Range("AL54").Value + 4)

..Cells(86, Range("AL54").Value + 4).Goalseek Goal:=.Range("AL86"),
ChangingCell:=.Cells(52, Range("AL54").Value + 4)

End If
End With

Next WS

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loop several sheets - part 4 - Dave Peterson - Goal seek

When your code is in a general module and you don't qualify the ranges, then
those unqualfied ranges refer to the activesheet.

So
Range("AL54").Value
is the same as:
Activesheet.Range("AL54").Value

So you can specify the sheet that contains that cell:

..Cells(84, worksheets("somesheetnamehere").Range("AL54").Valu e + 4)...

or

..Cells(84, .Range("AL54").Value + 4)....
if that AL54 should be picked up anew from each worksheet in the loop.

al wrote:

why do i have to start running this macro in a sheet in which AL54
has a value & not any other sheet outside selected "range" sheets??
Would prefer it to work when any sheet is active - thxs

Sub Goalseekoffsetall()

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

.Cells(84, Range("AL54").Value + 4).Goalseek Goal:=.Range("AL84"),
ChangingCell:=.Cells(50, Range("AL54").Value + 4)

.Cells(85, Range("AL54").Value + 4).Goalseek Goal:=.Range("AL85"),
ChangingCell:=.Cells(51, Range("AL54").Value + 4)

.Cells(86, Range("AL54").Value + 4).Goalseek Goal:=.Range("AL86"),
ChangingCell:=.Cells(52, Range("AL54").Value + 4)

End If
End With

Next WS

End Sub


--

Dave Peterson
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
Loop several sheets - part 3 - Dave Peterson - Goal seek al Excel Programming 4 January 25th 09 10:12 PM
Loop several sheets - part 2 - dave al Excel Programming 3 January 25th 09 02:30 PM
Excel -- Navigation Toolbar for Workbook Sheets -Dave Peterson Brenda Excel Discussion (Misc queries) 13 October 26th 08 08:37 PM
Do Loop Goal Seek won't End Sub Sharon Excel Programming 2 November 15th 07 04:27 AM
Goal Seek in a loop Brother Excel Discussion (Misc queries) 3 October 3rd 07 08:22 PM


All times are GMT +1. The time now is 02:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"