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 2 - dave

Have tried to adapt previous macro from previous post with different
range - but not working - can someone correct pls


Sub UpdateAllRevPeriod1()

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



Set RngToCopy = .Range("AM84:AM86")
RngToCopy.Copy
Range("AL84").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

End If
End With

Next WS

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Loop several sheets - part 2 - dave

Hi,

Just a slight problem with the paste range syntax. Note that now 2 lines are
combined (no need to select) and prefixed with . to make it part of the with
statement

Sub UpdateAllRevPeriod1()

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 seeingthe
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



Set RngToCopy = .Range("AM84:AM86")
RngToCopy.Copy
.Range("AL84").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

End If
End With

Next WS

End Sub


Mike


"al" wrote:

Have tried to adapt previous macro from previous post with different
range - but not working - can someone correct pls


Sub UpdateAllRevPeriod1()

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



Set RngToCopy = .Range("AM84:AM86")
RngToCopy.Copy
Range("AL84").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

End If
End With

Next WS

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loop several sheets - part 2 - dave

You dropped the dots in front of the range objects. Without those dots and the
corresponding "With" statements, the ranges will refer to the active sheet (if
the code is in a General module).

And you can only select a range on the sheet that is active. The good thing is
that you don't need to select a range for your code to work.

Untested, but it did compile:

Option Explicit
Sub UpdateAllRevPeriod1()

Dim WS As Worksheet
Dim MinIndex As Long
Dim MaxIndex As Long
Dim RngToCopy As Range

ActiveWorkbook.PrecisionAsDisplayed = False
'Prevents the user from seeing the screen
Application.ScreenUpdating = False

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
Set RngToCopy = .Range("AM84:AM86")
RngToCopy.Copy
.Range("AL84").PasteSpecial Paste:=xlPasteValues
End If
End With
Next WS

'just do it once at the end
Application.CutCopyMode = False

End Sub


al wrote:

Have tried to adapt previous macro from previous post with different
range - but not working - can someone correct pls

Sub UpdateAllRevPeriod1()

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

Set RngToCopy = .Range("AM84:AM86")
RngToCopy.Copy
Range("AL84").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

End If
End With

Next WS

End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default Loop several sheets - part 2 - dave

On Jan 25, 5:14 pm, Dave Peterson wrote:
You dropped the dots in front of the range objects. Without those dots and the
corresponding "With" statements, the ranges will refer to the active sheet (if
the code is in a General module).

And you can only select a range on the sheet that is active. The good thing is
that you don't need to select a range for your code to work.

Untested, but it did compile:

Option Explicit
Sub UpdateAllRevPeriod1()

Dim WS As Worksheet
Dim MinIndex As Long
Dim MaxIndex As Long
Dim RngToCopy As Range

ActiveWorkbook.PrecisionAsDisplayed = False
'Prevents the user from seeing the screen
Application.ScreenUpdating = False

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
Set RngToCopy = .Range("AM84:AM86")
RngToCopy.Copy
.Range("AL84").PasteSpecial Paste:=xlPasteValues
End If
End With
Next WS

'just do it once at the end
Application.CutCopyMode = False

End Sub



al wrote:

Have tried to adapt previous macro from previous post with different
range - but not working - can someone correct pls


Sub UpdateAllRevPeriod1()


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


Set RngToCopy = .Range("AM84:AM86")
RngToCopy.Copy
Range("AL84").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False


End If
End With


Next WS


End Sub


--

Dave Peterson


thxs u all for your support!!
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
Dave phlogiston appears in spreadsheet cell when I type Dave P tallsaint Excel Discussion (Misc queries) 2 September 4th 09 11:05 AM
Excel -- Navigation Toolbar for Workbook Sheets -Dave Peterson Brenda Excel Discussion (Misc queries) 13 October 26th 08 08:37 PM
Rename Multiple Sheets - Help with Mr Dave Peterson's Code [email protected] Excel Programming 2 January 4th 06 09:16 AM
Help with Mr. Dave Peterson's Code for Consolidating Many Sheets to One Rashid Khan Excel Programming 2 July 31st 04 07:31 PM
VLOOKUP PART 2....(Dave Paterson) wayne Excel Programming 7 May 27th 04 04:03 AM


All times are GMT +1. The time now is 12:07 PM.

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"