Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
carl
 
Posts: n/a
Default VBA Code To have a macro repeat on all sheets in a workbook

I am using this code:

Range("E9").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Selection.End(xlToRight).Select
Range("J9").Select
ActiveSheet.Paste
Range("J10").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-5]*RC2"
Range("J10").Select
ActiveWindow.SmallScroll Down:=-6
Selection.NumberFormat = "0"
Selection.Copy
Range("I10").Select
Selection.End(xlDown).Select
Range("J495:O495").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J494").Select
Selection.End(xlUp).Select
Range("J8").Select
ActiveCell.FormulaR1C1 = "=SUM(R[2]C:R[1000]C)/SUM(R10C2:R1000C2)"
Range("J8").Select
Selection.NumberFormat = "0.00%"
Selection.Copy
Range("K8:N8").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J9").Select
Selection.End(xlToLeft).Select
Range("C8").Select
ActiveCell.FormulaR1C1 =
"=SUM(R[2]C:R[1000]C)/SUM(R[2]C[-1]:R[1000]C[-1])"
Range("C8").Select
Selection.NumberFormat = "0.00%"
End Sub

Is it possible to add code to this that would allow the macro to be started
once and then repeat for each worksheet in my workbook ?

Thank you in advance..

  #2   Report Post  
Gary L Brown
 
Posts: n/a
Default VBA Code To have a macro repeat on all sheets in a workbook

Dim wksht As Worksheet
For Each wksht In Application.Worksheets
YOUR CODE HERE
Next wksht

HTH,
--
Gary Brown

If this post was helpful, please click the ''''Yes'''' button next to
''''Was this Post Helpfull to you?".


"carl" wrote:

I am using this code:

Range("E9").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Selection.End(xlToRight).Select
Range("J9").Select
ActiveSheet.Paste
Range("J10").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-5]*RC2"
Range("J10").Select
ActiveWindow.SmallScroll Down:=-6
Selection.NumberFormat = "0"
Selection.Copy
Range("I10").Select
Selection.End(xlDown).Select
Range("J495:O495").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J494").Select
Selection.End(xlUp).Select
Range("J8").Select
ActiveCell.FormulaR1C1 = "=SUM(R[2]C:R[1000]C)/SUM(R10C2:R1000C2)"
Range("J8").Select
Selection.NumberFormat = "0.00%"
Selection.Copy
Range("K8:N8").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J9").Select
Selection.End(xlToLeft).Select
Range("C8").Select
ActiveCell.FormulaR1C1 =
"=SUM(R[2]C:R[1000]C)/SUM(R[2]C[-1]:R[1000]C[-1])"
Range("C8").Select
Selection.NumberFormat = "0.00%"
End Sub

Is it possible to add code to this that would allow the macro to be started
once and then repeat for each worksheet in my workbook ?

Thank you in advance..

  #3   Report Post  
Otto Moehrbach
 
Posts: n/a
Default VBA Code To have a macro repeat on all sheets in a workbook

One way: HTH Otto

Sub AllSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
'Your code
Next
End Sub
"carl" wrote in message
...
I am using this code:

Range("E9").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Selection.End(xlToRight).Select
Range("J9").Select
ActiveSheet.Paste
Range("J10").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-5]*RC2"
Range("J10").Select
ActiveWindow.SmallScroll Down:=-6
Selection.NumberFormat = "0"
Selection.Copy
Range("I10").Select
Selection.End(xlDown).Select
Range("J495:O495").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J494").Select
Selection.End(xlUp).Select
Range("J8").Select
ActiveCell.FormulaR1C1 = "=SUM(R[2]C:R[1000]C)/SUM(R10C2:R1000C2)"
Range("J8").Select
Selection.NumberFormat = "0.00%"
Selection.Copy
Range("K8:N8").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J9").Select
Selection.End(xlToLeft).Select
Range("C8").Select
ActiveCell.FormulaR1C1 =
"=SUM(R[2]C:R[1000]C)/SUM(R[2]C[-1]:R[1000]C[-1])"
Range("C8").Select
Selection.NumberFormat = "0.00%"
End Sub

Is it possible to add code to this that would allow the macro to be
started
once and then repeat for each worksheet in my workbook ?

Thank you in advance..



  #4   Report Post  
Gary L Brown
 
Posts: n/a
Default VBA Code To have a macro repeat on all sheets in a workbook

Otto's right. I forgot that you're copying and pasting. So to keep your
code prestine you HAVE TO go to the worksheet prior to running your code.

Sincerely,
Gary Brown

If this post was helpful, please click the ''''Yes'''' button next to
''''Was this Post Helpfull to you?".


"Gary L Brown" wrote:

Dim wksht As Worksheet
For Each wksht In Application.Worksheets
YOUR CODE HERE
Next wksht

HTH,
--
Gary Brown

If this post was helpful, please click the ''''Yes'''' button next to
''''Was this Post Helpfull to you?".


"carl" wrote:

I am using this code:

Range("E9").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Selection.End(xlToRight).Select
Range("J9").Select
ActiveSheet.Paste
Range("J10").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=RC[-5]*RC2"
Range("J10").Select
ActiveWindow.SmallScroll Down:=-6
Selection.NumberFormat = "0"
Selection.Copy
Range("I10").Select
Selection.End(xlDown).Select
Range("J495:O495").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J494").Select
Selection.End(xlUp).Select
Range("J8").Select
ActiveCell.FormulaR1C1 = "=SUM(R[2]C:R[1000]C)/SUM(R10C2:R1000C2)"
Range("J8").Select
Selection.NumberFormat = "0.00%"
Selection.Copy
Range("K8:N8").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("J9").Select
Selection.End(xlToLeft).Select
Range("C8").Select
ActiveCell.FormulaR1C1 =
"=SUM(R[2]C:R[1000]C)/SUM(R[2]C[-1]:R[1000]C[-1])"
Range("C8").Select
Selection.NumberFormat = "0.00%"
End Sub

Is it possible to add code to this that would allow the macro to be started
once and then repeat for each worksheet in my workbook ?

Thank you in advance..

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
Extract specific data into its own workbook via macro? Adrian B Excel Discussion (Misc queries) 2 February 24th 05 06:09 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
How to hyperlink from a workbook to sheets in another workbook? MJOHNSON Excel Worksheet Functions 0 February 17th 05 08:31 PM
Copy comments to several sheets in a workbook? jen_l_333 Excel Worksheet Functions 1 January 7th 05 10:30 PM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM


All times are GMT +1. The time now is 11:23 AM.

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

About Us

"It's about Microsoft Excel"