Code runs but not from a button.

Russk68

Well-known Member
Joined
May 1, 2006
Messages
589
Office Version
  1. 365
Platform
  1. MacOS
On a Mac. This code runs fine from the editor but doesn't run from a shape with the macro assigned to it. I tried a few time just to make sure that I was assigning the correct macro.
Thanks in advance!
VBA Code:
Sub ToggleSheetVisibility()
    Dim shtName As Range
    Dim tabsUpdated As Boolean
    tabsUpdated = False
    For Each shtName In Range("L18:L42")
        On Error Resume Next ' <-- Ignore any sheets that are not found
        Dim sht As Worksheet
        Set sht = Worksheets(shtName.Value)
        If Not sht Is Nothing Then
            Dim col As Integer
            For col = 11 To 12 ' <-- Loop through columns K to L
                If Cells(shtName.Row, col).Value = True Then
                    sht.Visible = True ' <-- Unhides the sheet
                    tabsUpdated = True
                    Exit For
                End If
            Next col
            If col = 13 Then ' <-- None of the cells were true
                sht.Visible = False ' <-- Hides the sheet
                tabsUpdated = True
            End If
        End If
    Next shtName
    If tabsUpdated Then
        MsgBox "Tabs were updated"
    End If
End Sub
/CODE]
 
Thanks for letting us know what you did to fix it. I will add it to my list of things to look out for.
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top