Macro Code Only Work in Visible Sheets [Expected]

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
1,822
Office Version
  1. 2013
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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,847
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
Hi,
Use this modified code line:
Rich (BB code):
If ws.Visible And ws.Name <> ActiveSheet.Name And ws.Name <> "etc.." Then
 
Solution

Forum statistics

Threads
1,148,191
Messages
5,745,257
Members
423,941
Latest member
CluelessAboutExcel

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
Top