VBA not breaking but not working

Vally 88

New Member
Joined
Nov 20, 2017
Messages
19
Hello All,

I'm trying to create a Hide- show VBA based on *name* for different tabs. Please find code below:
Code:
Sub hide_Arabic_tabs()


    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next
        Select Case True
            Case LCase(ws.Name) Like "*Arabic*"
            ws.Visible = xlSheetHidden
            Case Else
        End Select
    Next ws


End Sub
Sub show_Arabic_tabs()


    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next
        Select Case True
            Case LCase(ws.Name) Like "*Arabic*"
            ws.Visible = xlSheetVisible
            Case Else
        End Select
    Next ws
    End Sub
I have 18 of them in a module and they are linked to a button. I'm sure the VBA is correct since I'm currently using it with other name conditions in other module, eg below:
Code:
Sub hide_raw_tabs()


    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next
        Select Case True
            Case LCase(ws.Name) Like "*raw*"
            ws.Visible = xlSheetHidden
            Case Else
        End Select
    Next ws


End Sub
Sub show_raw_tabs()


    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next
        Select Case True
            Case LCase(ws.Name) Like "*raw*"
            ws.Visible = xlSheetVisible
            Case Else
        End Select
    Next ws
    End Sub
It's probably worth saying that the 2 macros can affect the same sheet, so to make it clear I have a tab called Arabic Raw Data. I want this one showing or hiding with both macros "*raw*" and "*Arabic*". Unfortunately my macros based on languages are running (not breaking) but not working while raw is working perfectly. Anyone has any clue why? I have tried to have them in a unique module as well as 2 different ones but it'snot making any difference.

Hope any of you got a better idea :) thank you in advance!!!

Valeria
 
Last edited by a moderator:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi, welcome to the forum!

Case LCase(ws.Name) Like "*Arabic*

LCase() is returning the sheet name in lower case, so your comparison text (red above) also needs to be in lower case.
 
Last edited:
Upvote 0
Hi, the problem is that you are looking at the lowercase of worksheet.name, but comparing it to Arabic which is not lowercase. change Arabic to arabic & you should be ok
 
Upvote 0
thank you very much all of you!!

this was the case, I'm stupid I didn't think about it!!!

Cheers!!!!
 
Upvote 0
Welcome to the forum.

You can streamline your code a lot by refactoring into one routine that takes a sheet name to compare and an option to hide or show the tabs, like this:

Code:
Sub hide_Arabic_tabs()
    tabsVisible "Arabic", False
End Sub
Sub show_Arabic_tabs()
    tabsVisible "Arabic", True
End Sub
Sub hide_raw_tabs()
    tabsVisible "raw", False
End Sub
Sub show_raw_tabs()
    tabsVisible "raw", True
End Sub
Sub tabsVisible(sName As String, Optional bVisible As Boolean = True)
    Dim ws As Worksheet
    sName = LCase$(sName)
    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next
        If LCase(ws.Name) Like "*" & sName & "*" Then
            If bVisible Then
                ws.Visible = xlSheetVisible
            Else
                ws.Visible = xlSheetHidden
            End If
        End If
    Next ws

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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