Help to check sheet name then do something

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
74
Hi all I have code below work well but I want to change this line:
<code style="box-sizing: border-box; font-family: inherit; font-size: 1em;">If Sh.Name <> "LocKH" And Sh.Name <> "Ma" Then
to

<code style="box-sizing: border-box; font-family: inherit; font-size: 1em;">If Sh.Name = array(A,B,C,D,E,F) Then

Please help me, thanks./.</code></code></pre>
Code:
[COLOR=#141414][FONT=inherit]Option Explicit[/FONT][/COLOR]<code style="box-sizing: border-box; font-family: inherit; font-size: 1em;">
Sub filter()
    Application.ScreenUpdating = False
    Dim a, b(1 To 65000, 1 To 15), lR, Sh As Worksheet, endR As Long, i As Long, j As Long, k As Long
    Dim ii As Long, Data As Variant

    Sheets("LocKH").Range("b5:q5000").ClearContents
    endR = Sheets("Ma").Range("B" & Rows.Count).End(3).Row + 1
    
    If endR < 4 Then Exit Sub
    Data = Sheets("Ma").Range("B3:B" & endR).Value    '
    endR = UBound(Data) - 1
    For Each Sh In ThisWorkbook.Worksheets
       [COLOR=#ff0000] If Sh.Name <> "LocKH" And Sh.Name <> "Ma" Then [/COLOR]   '
            'do something
        End If
    Next
    Application.ScreenUpdating = True </code>[COLOR=#141414][FONT=inherit]End Sub[/FONT][/COLOR]
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
7,927
Office Version
365
Platform
Windows
What do you mean? Your sheets are called A or B or C etc?
 

MoshiM

Active Member
Joined
Jan 31, 2018
Messages
305
Hi all I have code below work well but I want to change this line:
<code style="box-sizing: border-box; font-family: inherit; font-size: 1em;">If Sh.Name <> "LocKH" And Sh.Name <> "Ma" Then
to

<code style="box-sizing: border-box; font-family: inherit; font-size: 1em;">If Sh.Name = array(A,B,C,D,E,F) Then

Please help me, thanks./.</code></code>
Code:
if not iserror(application.match(Sh.name,split("A,B,C,D,E,F",","),0))
 
Last edited:

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
7,927
Office Version
365
Platform
Windows
What about this:

Code:
shArr = Array("Sheet1", "Sheet5")

For i = LBound(shArr) To UBound(shArr)
    Set sh = Sheets(shArr(i))
    MsgBox sh.Name
Next
 

Watch MrExcel Video

Forum statistics

Threads
1,090,329
Messages
5,413,830
Members
403,504
Latest member
rosebo

This Week's Hot Topics

Top