Macro Code Only Work in Visible Sheets [Expected]

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi expert..
this code working well for all sheet included hidden sheets.
i want to the code only work in visible sheets not included hidden sheets
VBA Code:
Sub Consolidate_Worksheets()
    Dim ws          As Worksheet
    Dim sh          As Worksheet
    Dim a           As Variant
    Dim i           As Long
    Dim R           As Long
    
    Application.ScreenUpdating = False
        Set sh = ActiveSheet
        sh.Range("A1").CurrentRegion.Offset(1).ClearContents
        R = 2
        
        For Each ws In ActiveWorkbook.Worksheets
            If ws.Name <> ActiveSheet.Name And ws.Name <> "etc.." Then
                With ws
                    a = Array("a1", "a5", "a6", "a7", "a8", "a8", "a9", "a10", "b5", "b6", "b7", "b8", "b9", "b10" _
                    , "c5", "c6", "c7", "c8", "c9", "c10", "f5", "f6", "f7", "f8", "f9", "f10", "g5", "g6" _
                    , "g7", "g8", "g9", "g10", "h5", "h6", "h7", "h8", "h9", "h10")
                    For i = LBound(a) To UBound(a)
                        a(i) = .Range(a(i)).Value
                        If i >= 100000 Then a(i) = Val(AlphaNum(CStr(a(i))))
                    Next i
                    sh.Range("A" & R).Resize(, UBound(a) + 1).Value = a
                    R = R + 1
                End With
            End If
        Next ws
    Application.ScreenUpdating = True
End Sub
Function AlphaNum(txt As String, Optional numOnly As Boolean = True) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = IIf(numOnly = True, "\D+", "-?\d+(\.\d+)?")
        .Global = True
        AlphaNum = .Replace(txt, "")
    End With
End Function
how to modify that code
someone figure out me, thank in advance..
.sst
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,
Use this modified code line:
Rich (BB code):
If ws.Visible And ws.Name <> ActiveSheet.Name And ws.Name <> "etc.." Then
 
Upvote 0
Solution

Forum statistics

Threads
1,214,581
Messages
6,120,368
Members
448,957
Latest member
BatCoder

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