|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
how to run a macro to mutliple files
I am a newbie and have to run a macro on 114 files. Can anyone help me>?> Thanks
|
|
#2
|
|||
|
|||
|
Post a few details of your environment and what you're trying to do.
|
|
#3
|
|||
|
|||
|
here is what i came up with
Sub loopyarray()
Dim filenames As Variant ' set the array to a variable and the True is for multi-select filenames = Application.GetOpenFilename(, , , , True) counter = 1 ' ubound determines how many items in the array While counter <= UBound(filenames) 'Opens the selected files Workbooks.Open filenames(counter) If Sheets.Count = 1 Then Digits = 1 ElseIf Sheets.Count = 2 Then ' Condition evaluates to True so the next statement is executed. Digits = 2 Else Digits = 3 End If If Digits = 1 Then Sheets(1).Select Else: Sheets(Array((1), (2), (3))).Select Cells.Select Selection.Replace What:="FY03", Replacement:="fy04", LookAt:=xlPart, _ SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Cells.Select Selection.Replace What:="Cur Bud/Fcst", Replacement:="Cur Bud-Fcst", LookAt:=xlPart, _ SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Range( _ "B3 5,F3:H5,J3:L5,N3:P5,N7:P13,N15:P18,J7:L13,J15:L18,F7:H13,F15:H18,B7 13,B15 18" _).Select Range("B15").Activate Selection.Locked = False Selection.FormulaHidden = False Selection.ClearContents Range("E3").Select ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:RC[-1])" Range("E3").Select Selection.Copy Range("E3:E20").Select Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("B6").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)" Range("B6").Select Selection.Copy Application.CutCopyMode = False Selection.Copy Range("B6:R6").Select Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("B14").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(R[-7]C:R[-1]C)" Range("B14").Select Selection.Copy Range("B14:R14").Select Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("B19").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(R[-4]C:R[-1]C)" Range("B19").Select Selection.Copy Range("B19:R19").Select Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("B20").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(R[-14]C,R[-6]C,R[-1]C)" Range("B20").Select Selection.Copy Range("B20:R20").Select Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("E3").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:RC[-1])" Range("E3").Select Selection.Copy Range("E4,E5,E7:E13,E15:E18").Select Range("E15").Activate ActiveSheet.Paste Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("I3").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:RC[-1])" Range("I3").Select Selection.Copy Range("I3:I5,I7:I13,I15:I18").Select Range("I15").Activate Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("M3").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:RC[-1])" Range("M3").Select Selection.Copy Range("M4:M5,M7:M13,M15:M18").Select Range("M15").Activate Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("Q3").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(RC[-3]:RC[-1])" Range("Q3").Select Selection.Copy Range("Q4:Q5,Q7:Q13,Q15:Q18").Select Range("Q15").Activate Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("R3").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "=SUM(RC[-13],RC[-9],RC[-5],RC[-1])" Range("R3").Select Selection.Copy Range("R3:R5,R7:R13,R15:R18").Select Range("R15").Activate Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Range("b3").Select Application.CutCopyMode = False If Sheets.Count = 1 Then Sheets(1).Select ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True Else: Sheets("Sales").Select ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("FW").Select ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("Apparel").Select ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True End If Sheets(1).Select ActiveWorkbook.Save ActiveWorkbook.Close 'increment counter counter = counter + 1 Wend End Sub |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > how to run a macro to mutliple files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|