VBA Strikethrough sheet tab name with checkbox

EtienneD

New Member
Joined
Jul 21, 2022
Messages
27
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have 5 worksheets that represent 5 different lists of tasks. When all the tasks are done in one sheet, I want to be able to to see it quickly. So I would like to have a checkbox that either strikethrough that tab name so we know it's all done. I know how to add the checkbox, name it with the tab name I want to modify , and assign the macro to the checkbox. I just needhelp with the formula please.

Thanks to you all
 
Hi EtienneD

Check out this workbook example : StrikeThroughTabs.xlsm




The following function should toggle the worksheet tab strikethrough on and off .via a checkbox control embedded in the worksheet as requested.


In a Standard Module:
VBA Code:
Option Explicit

Function StrikeThrough_Worksheet_Tab( _
    ByVal WS As Worksheet, _
    Optional ByVal bStrike As Boolean = True _
    ) As Boolean

    Const MAX_CHARS = 15
    Dim i As Long, sTmp As String
    
    With WS
        Select Case bStrike
            Case True
                If AscW(Mid(.Name, 1, 1)) <> &H335 And Len(.Name) <= MAX_CHARS Then
                    For i = 1 To Len(.Name)
                        sTmp = sTmp & ChrW(&H335) & Mid(.Name, i, 1)
                    Next i
                    .Name = sTmp & ChrW(&H335)
                    StrikeThrough_Worksheet_Tab = True
                End If
            Case Else
                If AscW(Mid(.Name, 1, 1)) = &H335 Then
                    .Name = Replace(.Name, ChrW(&H335), "")
                End If
                StrikeThrough_Worksheet_Tab = True
        End Select
    End With

End Function


Sub CheckBox_Macro()
    
    If StrikeThrough_Worksheet_Tab( _
        WS:=ActiveSheet, _
        bStrike:=CBool(ActiveSheet.Shapes(Application.Caller).ControlFormat.Value And &H1) _
    ) = False Then
        
      MsgBox "Failed to striketrough the current worksheet tab!" & vbNewLine & vbNewLine & _
            "Tab names must not exceed 15 characters.", vbCritical, "ERROR"
   End If
        
End Sub
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi EtienneD

Check out this workbook example : StrikeThroughTabs.xlsm




The following function should toggle the worksheet tab strikethrough on and off .via a checkbox control embedded in the worksheet as requested.


In a Standard Module:
VBA Code:
Option Explicit

Function StrikeThrough_Worksheet_Tab( _
    ByVal WS As Worksheet, _
    Optional ByVal bStrike As Boolean = True _
    ) As Boolean

    Const MAX_CHARS = 15
    Dim i As Long, sTmp As String
   
    With WS
        Select Case bStrike
            Case True
                If AscW(Mid(.Name, 1, 1)) <> &H335 And Len(.Name) <= MAX_CHARS Then
                    For i = 1 To Len(.Name)
                        sTmp = sTmp & ChrW(&H335) & Mid(.Name, i, 1)
                    Next i
                    .Name = sTmp & ChrW(&H335)
                    StrikeThrough_Worksheet_Tab = True
                End If
            Case Else
                If AscW(Mid(.Name, 1, 1)) = &H335 Then
                    .Name = Replace(.Name, ChrW(&H335), "")
                End If
                StrikeThrough_Worksheet_Tab = True
        End Select
    End With

End Function


Sub CheckBox_Macro()
   
    If StrikeThrough_Worksheet_Tab( _
        WS:=ActiveSheet, _
        bStrike:=CBool(ActiveSheet.Shapes(Application.Caller).ControlFormat.Value And &H1) _
    ) = False Then
       
      MsgBox "Failed to striketrough the current worksheet tab!" & vbNewLine & vbNewLine & _
            "Tab names must not exceed 15 characters.", vbCritical, "ERROR"
   End If
       
End Sub
It works like a charm. Thank very much!
 
Upvote 0

Forum statistics

Threads
1,216,484
Messages
6,130,936
Members
449,608
Latest member
jacobmudombe

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