(Solved) – Apply VBA macro to specific sheets

(solved)-–-apply-vba-macro-to-specific-sheets

I have a macro which I wish to apply to specific sheets depending on their name. For example, if sheet name is “Bore 4” then run “groundwater_macro1”

Sub Specify()

    Dim Fun As String
    Dim Sht As Worksheet

    For Each Sht In Worksheets
        Select Case Sht.Name
            Case "NB12", "NB15"
                Application.Run "Groundwater_Macros.xlsm!limits_Alluvium"
            Case "NB24"
                Application.Run "Groundwater_Macros.xlsm!limits_BOCOBOML_GFA"
            Case "NB16", "NB17", "NB19", "NB20", "Bore 31"
                Application.Run "Groundwater_Macros.xlsm!limits_BOCOBOML_MIA"
            Case "Bore 47", "Bore 48"
                Application.Run "Groundwater_Macros.xlsm!limits_FracturedRock_GFA"
            Case "Bore 4", "Bore 4a", "Bore 40"
                Application.Run "Groundwater_Macros.xlsm!limits_FracturedRock_MIA_West"
            Case "Bore 30"
                Application.Run "Groundwater_Macros.xlsm!limits_FracturedRock_MIA_East"
            Case Else
                Application.Run "Groundwater_Macros.xlsm!limits_Monitoring_bores"

        End Select
    Next Sht

End Sub

I have this code but it only seems to use the Case Else call

Leave a Reply

Your email address will not be published. Required fields are marked *