Show worksheets independently using macro assigned buttons

Delvestio

New Member
Joined
Oct 8, 2024
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi all, i'm brand new at this and would like to politely ask you wonderful people if you could spare the time to help me with a problem:

I have one WorkBook.
This WorkBook contains 14 WorkSheets and Summary Sheet.
The Summary Sheet is a constant and always shown.
The WorkSheets are all hidden by default.
Within the Summary Sheet there are cells which contain the names of the WorkSheets, as follows:

Buildings
Contents
Jewellery
Jewellery (Specified)
Art & Antiques
Alternative Accommodation
Preventative Measures
Electricity Calcs

I need to have a button assigned to each cell that when clicked Shows the WorkSheet.

Help me.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I really appreciate your help Dave

Looks like you have placed the code in a Sheet code page. Code MUST be placed in a STANDARD module

Delete the Code & the from the VBA Editor Insert > Module
Now place the code in the module.
With the Summary Sheet Active, run the AssignShapes code.

Dave
 
Upvote 0
Looks like you have placed the code in a Sheet code page. Code MUST be placed in a STANDARD module

Delete the Code & the from the VBA Editor Insert > Module
Now place the code in the module.
With the Summary Sheet Active, run the AssignShapes code.

Dave
Thanks Dave, I followed your instructions and this threw of a mismatch error: I ran the debug - screen shots attached.
 

Attachments

  • Screenshot 2024-10-09 074755.png
    Screenshot 2024-10-09 074755.png
    36.8 KB · Views: 3
  • Screenshot 2024-10-09 074820.png
    Screenshot 2024-10-09 074820.png
    75.9 KB · Views: 3
Upvote 0
It may be that a name in your range is not valid

can you comment out the lines shown in the code below & then try running it again

Rich (BB code):
           'If Evaluate("ISREF('" & sh & "'!A1)") Then
                Worksheets(sh).Visible = IIf(sh = SheetName, xlSheetVisible, xlSheetVeryHidden)
           ' End If
 
Upvote 0
further thoughts I am guessing you may have another shape in column C that is not assigned to a sheet name (empty cell)

try this update to the ShowSheet code & see if resolves the issue

VBA Code:
Sub ShowSheet(ByVal SheetName As String)
    Dim sh          As String
    Dim shp         As Shape
   
    Application.ScreenUpdating = False
    For Each shp In ActiveSheet.Shapes
        If shp.TopLeftCell.Column = 3 Then
            sh = shp.TopLeftCell.Value
            If Len(sh) > 0 Then
                If Evaluate("ISREF('" & sh & "'!A1)") Then
                    Worksheets(sh).Visible = IIf(sh = SheetName, xlSheetVisible, xlSheetVeryHidden)
                End If
            End If
        End If
    Next shp
    Application.ScreenUpdating = True
   
End Sub

Dave
 
Upvote 0
further thoughts I am guessing you may have another shape in column C that is not assigned to a sheet name (empty cell)

try this update to the ShowSheet code & see if resolves the issue

VBA Code:
Sub ShowSheet(ByVal SheetName As String)
    Dim sh          As String
    Dim shp         As Shape
  
    Application.ScreenUpdating = False
    For Each shp In ActiveSheet.Shapes
        If shp.TopLeftCell.Column = 3 Then
            sh = shp.TopLeftCell.Value
            If Len(sh) > 0 Then
                If Evaluate("ISREF('" & sh & "'!A1)") Then
                    Worksheets(sh).Visible = IIf(sh = SheetName, xlSheetVisible, xlSheetVeryHidden)
                End If
            End If
        End If
    Next shp
    Application.ScreenUpdating = True
  
End Sub

Dave
Ok, so this has resolved the issue and the buttons now work without throwing up an error. However, the result is not what is required.

E.G., When I click the arrow within the Buildings Column C cell - this works perfectly and shows the Buildings tab (previously hidden). However, when I then click the arrow in the Contents cell it replaces the Buildings tab with the contents tab. I need it to show any and all tabs that has been clicked.
 
Upvote 0
Ok, so this has resolved the issue and the buttons now work without throwing up an error. However, the result is not what is required.

E.G., When I click the arrow within the Buildings Column C cell - this works perfectly and shows the Buildings tab (previously hidden). However, when I then click the arrow in the Contents cell it replaces the Buildings tab with the contents tab. I need it to show any and all tabs that has been clicked.

You need to ensure that each Shape sits within the appropriate cell (must not overlap another cell) & then with the summary sheet active, run the AssignShapes code again.

Dave
 
Upvote 0
You need to ensure that each Shape sits within the appropriate cell (must not overlap another cell) & then with the summary sheet active, run the AssignShapes code again.

Dave
Looks fine to me...
 

Attachments

  • Screenshot 2024-10-09 114258.png
    Screenshot 2024-10-09 114258.png
    26.4 KB · Views: 1
Upvote 0
Looks fine to me...
Did you re-run the AssignShapes code?

If still having problems, place copy of your workbook (with no data) on a file sharing site like dropbox & provide a link to it here.
 
Upvote 0

Forum statistics

Threads
1,222,903
Messages
6,168,939
Members
452,227
Latest member
sam1121

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