Christopher J Rode
Christopher J Rode

Reputation: 11

Running all my Macros In excel instead of one by one

I wrote a few small Macros since I am not very good at this and all of them work however I would like to run all of these at once or in order as they are written. I tried to use a call but this didnt work for some reason. Basically what I have done is some basic formatting for a file so it can be pasted into another file. Attached is the macros I have so far. I exported this into a text file to share and I am importing the file into excel so it can be used on any file by anyone who does this but I need the macros to all run instead of one by one. Any advice? Thank you so much.

Sub RemoveHyperlink()
' ' RemoveHyperlink Macro '

    '
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Hyperlinks.Delete
    End Sub
Sub RemoveFill()

' ' RemoveFill Macro '

    '
    Range("A1:G604").Select
    With Selection.Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
    Range("C3").Select
End Sub

Sub RemoveBold()

' ' RemoveBold Macro '

    '
    Cells.Select
    Selection.Font.Bold = True
    Selection.Font.Bold = False
End Sub

Sub RemoveBoarders()

' ' RemoveBoarders Macro '

    Cells.Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub

Sub FreezePanes()

' ' FreezePanes Macro '

    Rows("12:12").Select
    ActiveWindow.FreezePanes = True
    Range("K21").Select
End Sub

Sub DeleteColumn_C()

' ' DeleteColumn_C Macro '

    Columns("C:C").Select
    Selection.Delete Shift:=xlToLeft
    Range("J22").Select
End Sub

Sub SortData()
' ' SortData Macro '

    '
    Range("A11:G1048576").Select
    Range("G1048576").Activate
    ActiveWorkbook.Worksheets("FNDWRR").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("FNDWRR").Sort.SortFields.Add2 Key:=Range("A12:A604"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= xlSortNormal
    With ActiveWorkbook.Worksheets("FNDWRR").Sort
        .SetRange Range("A11:G604")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("J28").Select
End Sub

Sub InsertColums_5()

' ' InsertColums_5 Macro '

    '
    Columns("D:H").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove End Sub Sub TextToColumns() ' '
    TextToColumns Macro                          '

    '
    ActiveWindow.SmallScroll Down:=-9
    Range("C12").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.TextToColumns Destination:=Range("C12"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=True, Other:=True, OtherChar:= _
        ".", FieldInfo:=Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), _
                              Array(6, 2)), TrailingMinusNumbers:=True
End Sub

Sub CopyAccountsto_A()
' ' CopyAccountsto_A Macro '

    '
    ActiveWindow.SmallScroll Down:=-6
    Range("D12").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("A12").Select
    ActiveSheet.Paste
    Range("D7").Select
End Sub

Sub DeleteColumn_D()
' ' DeleteColumn_D Macro '

    '
    Columns("D:D").Select
    Selection.Delete Shift:=xlToLeft
    Range("D8").Select End Sub Sub AddTextToHeaders() ' ' AddTextToHeaders Macro '

    '
    Range("C11").Select
    ActiveCell.FormulaR1C1 = "DIV"
    Range("D11").Select
    ActiveCell.FormulaR1C1 = "CCTR"
    Range("E11").Select
    ActiveCell.FormulaR1C1 = "Proj"
    Range("F11").Select
    ActiveCell.FormulaR1C1 = "Fut"
    Range("G11").Select
    ActiveCell.FormulaR1C1 = "I/C"
    Range("G10").Select
End Sub

Sub AddGridlines()
' ' AddGridlines Macro '

    '
    ActiveWindow.DisplayGridlines = True

End Sub

Sub RunOrder()

    Call RemoveHyperlink
    Call RemoveFill
    Call RemoveBold
    Call ReomveBoarders
    Call FreezePanes
    Call DeleteColumn_C
    Call SortData
    Call InsertColumns_5
    Call TextToColumns
    Call CopyAccountsto_A
    Call DeleteColumn_D
    Call AddTextToHeaders
    Call AddGridlines

End Sub

Upvotes: 0

Views: 91

Answers (2)

AJD
AJD

Reputation: 2438

Always. Always. Always. Put Option Explicit at the top of modules.

IF you had done so, you would have been provided with some additional information and then a line would have been highlighted:

Sub RunOrder()
    RemoveHyperlink
    RemoveFill
    RemoveBold
    ReomveBoarders ' <-- Typing error
    FreezePanes
    DeleteColumn_C
    SortData
    InsertColumns_5 ' <--- typing error
    TextToColumns
    CopyAccountsto_A
    DeleteColumn_D
    AddTextToHeaders
    AddGridlines
End Sub

While not essential to the answer, the keyword Call is a hangover from very old VB syntax and is not required. At one stage MS marked this keyword as deprecated although I cannot find the reference these days. Code reads better without it.

The key point, and the solution to your question is:

Always. Always. Always. Put Option Explicit at the top of modules.

Upvotes: 3

zip
zip

Reputation: 4061

It didnt work because we have some mistake on the names:

Sub RunOrder()

Call RemoveHyperlink
Call RemoveFill
Call RemoveBold
Call RemoveBoarders # not ReomveBoarders
Call FreezePanes
Call DeleteColumn_C
Call SortData
Call InsertColums_5 # and not InsertColumns_5
Call TextToColumns
Call CopyAccountsto_A
Call DeleteColumn_D
Call AddTextToHeaders
Call AddGridlines

End Sub

Upvotes: 1

Related Questions