smashclash
Board Regular
- Joined
- Nov 24, 2003
- Messages
- 126
- Office Version
- 365
- Platform
- Windows
I have a lot of files that need a macro run. Currently, I have to open a workbook, run the macro and then go to the next one.
I'm looking for the code to run the macro on all open workbooks. I'd rather not have the macro open each workbook, perform the changes, and then save. I simply want a macro that runs on one workbook, when its finished it moves to the next one until there are no workbooks left. Is there a simple code to do this? I tried doing some searches and due to my limited VB experience I had trouble deciphering which would work for my situation.
Not sure if this is needed or not but below is a copy of the macro I run.
I'm looking for the code to run the macro on all open workbooks. I'd rather not have the macro open each workbook, perform the changes, and then save. I simply want a macro that runs on one workbook, when its finished it moves to the next one until there are no workbooks left. Is there a simple code to do this? I tried doing some searches and due to my limited VB experience I had trouble deciphering which would work for my situation.
Not sure if this is needed or not but below is a copy of the macro I run.
Code:
Sub YTD()
'
' YTD Macro
' Macro recorded 3/10/2004 by CollaT
'
'
Sheets("feb").Copy After:=Sheets(13)
Sheets("feb (2)").Select
Sheets("feb (2)").Name = "YTD"
Range("A4:C4").Select
ActiveCell.FormulaR1C1 = "YTD BALANCE"
Range("A4:C4").Select
ActiveCell.FormulaR1C1 = "2004 YTD BALANCE"
Range("A7").Select
ActiveCell.FormulaR1C1 = "Days in the Year"
Range("A8").Select
ActiveCell.FormulaR1C1 = "Hours in the Year"
Range("E7").Select
ActiveCell.FormulaR1C1 = "366"
Range("E14").Select
ActiveCell.FormulaR1C1 = _
"=+jan!RC+feb!RC+mar!RC+apr!RC+may!RC+june!RC+july!RC+aug!RC+sept!RC+oct!RC+nov!RC+dec!RC"
Range("E14").Select
If Len(ActiveCell.Offset(1, 0)) > 0 Then
ActiveCell.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Range("G14").Select
ActiveCell.FormulaR1C1 = _
"=+jan!RC+feb!RC+mar!RC+apr!RC+may!RC+june!RC+july!RC+aug!RC+sept!RC+oct!RC+nov!RC+dec!RC"
Range("G14").Select
If Len(ActiveCell.Offset(1, 0)) > 0 Then
ActiveCell.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Range("K14").Select
ActiveCell.FormulaR1C1 = _
"=+jan!RC+feb!RC+mar!RC+apr!RC+may!RC+june!RC+july!RC+aug!RC+sept!RC+oct!RC+nov!RC+dec!RC"
Range("K14").Select
If Len(ActiveCell.Offset(1, 0)) > 0 Then
ActiveCell.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Range("M14").Select
ActiveCell.FormulaR1C1 = _
"=+jan!RC+feb!RC+mar!RC+apr!RC+may!RC+june!RC+july!RC+aug!RC+sept!RC+oct!RC+nov!RC+dec!RC"
Range("M14").Select
If Len(ActiveCell.Offset(1, 0)) > 0 Then
ActiveCell.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Range("Y14").Select
ActiveCell.FormulaR1C1 = _
"=+jan!RC+feb!RC+mar!RC+apr!RC+may!RC+june!RC+july!RC+aug!RC+sept!RC+oct!RC+nov!RC+dec!RC"
Range("Y14").Select
If Len(ActiveCell.Offset(1, 0)) > 0 Then
ActiveCell.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Range("AA14").Select
ActiveCell.FormulaR1C1 = _
"=+jan!RC+feb!RC+mar!RC+apr!RC+may!RC+june!RC+july!RC+aug!RC+sept!RC+oct!RC+nov!RC+dec!RC"
Range("AA14").Select
If Len(ActiveCell.Offset(1, 0)) > 0 Then
ActiveCell.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Range("A1").Select
End Sub