Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Get macro to run on all sheets not just the active sheet

I am new to macros and visual basic. I am trying to get what is found below
to run on all worksheets not just the active sheet which is happening now.

Thank you. (Sorry for the double post in Excel Worksheet Functions)


Sub stock1()
'
' stock1 Macro
'
' Keyboard Shortcut: Ctrl+y
'

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ActiveWorkbook.RefreshAll
Next
For Each ws In ActiveWorkbook.Worksheets
Cells.Find(What:="put options", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Range("A1:P317").Select
Selection.Cut
ActiveCell.Offset(-14, 12).Range("A1").Select
Cells.Find(What:="call options", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 17).Range("A1").Select
ActiveSheet.Paste
Next
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Get macro to run on all sheets not just the active sheet

Option Explicit
Sub stock1()

Dim ws As Worksheet
Dim FoundPutCell As Range
Dim FoundCallCell As Range

ActiveWorkbook.RefreshAll

For Each ws In ActiveWorkbook.Worksheets
With ws
Set FoundPutCell = .Cells.Find(What:="put options", _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundPutCell Is Nothing Then
'not found on this sheet
Else
Set FoundCallCell = .Cells.Find(What:="Call options", _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundCallCell Is Nothing Then
'no call options found
Else
FoundPutCell.Range("A1:P317").Cut _
Destination:=FoundCallCell.Offset(0, 17)
End If
End If
End With
Next ws
End Sub


trey1982 wrote:

I am new to macros and visual basic. I am trying to get what is found below
to run on all worksheets not just the active sheet which is happening now.

Thank you. (Sorry for the double post in Excel Worksheet Functions)

Sub stock1()
'
' stock1 Macro
'
' Keyboard Shortcut: Ctrl+y
'

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ActiveWorkbook.RefreshAll
Next
For Each ws In ActiveWorkbook.Worksheets
Cells.Find(What:="put options", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Range("A1:P317").Select
Selection.Cut
ActiveCell.Offset(-14, 12).Range("A1").Select
Cells.Find(What:="call options", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 17).Range("A1").Select
ActiveSheet.Paste
Next
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Get macro to run on all sheets not just the active sheet

Works like a charm. Thank you.

"Dave Peterson" wrote:

Option Explicit
Sub stock1()

Dim ws As Worksheet
Dim FoundPutCell As Range
Dim FoundCallCell As Range

ActiveWorkbook.RefreshAll

For Each ws In ActiveWorkbook.Worksheets
With ws
Set FoundPutCell = .Cells.Find(What:="put options", _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundPutCell Is Nothing Then
'not found on this sheet
Else
Set FoundCallCell = .Cells.Find(What:="Call options", _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If FoundCallCell Is Nothing Then
'no call options found
Else
FoundPutCell.Range("A1:P317").Cut _
Destination:=FoundCallCell.Offset(0, 17)
End If
End If
End With
Next ws
End Sub


trey1982 wrote:

I am new to macros and visual basic. I am trying to get what is found below
to run on all worksheets not just the active sheet which is happening now.

Thank you. (Sorry for the double post in Excel Worksheet Functions)

Sub stock1()
'
' stock1 Macro
'
' Keyboard Shortcut: Ctrl+y
'

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ActiveWorkbook.RefreshAll
Next
For Each ws In ActiveWorkbook.Worksheets
Cells.Find(What:="put options", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Range("A1:P317").Select
Selection.Cut
ActiveCell.Offset(-14, 12).Range("A1").Select
Cells.Find(What:="call options", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 17).Range("A1").Select
ActiveSheet.Paste
Next
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
macro to find cell content in sheets and make sheet active Nigel Excel Discussion (Misc queries) 4 June 26th 14 02:38 PM
Run macro when Sheets are active Ed Davis[_2_] Excel Discussion (Misc queries) 2 October 1st 09 04:54 PM
Make global Macro/Add-in for all active Workbooks/Sheets SunRace Excel Programming 6 January 28th 08 12:40 PM
ow can I get the active sheet name to a var in a macro?? italo Excel Programming 1 May 16th 06 10:36 PM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Excel Programming 3 January 23rd 06 09:57 PM


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