Help to check sheet name then do something

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
72
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]
 

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
7,712
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
271
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,712
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
 

Forum statistics

Threads
1,077,638
Messages
5,335,393
Members
399,015
Latest member
emalabel

Some videos you may like

This Week's Hot Topics

Top