Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Excel 2010 macro issue on tab. Original title: Excel 2010. Hello there, I have t

ID: 3562829 • Letter: E

Question

Excel 2010 macro issue on tab.

Original title: Excel 2010.

Hello there,

I have the following two macro's and would like it to run on specific tabs not just one tab:

Sub FilterCenterColumns()

Dim wsInput As Worksheet
Set wsInput = Sheet4
wsInput.Select
ActiveSheet.Unprotect Password:="cfs101"
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

Dim MyRange As Range
Dim c As Range

Set MyRange = ActiveSheet.Range("F3:AK3")

For Each c In MyRange
If c.Value = "x" Then

Columns(c.Column).Hidden = True
End If
Next

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
ActiveSheet.Protect Password:="cfs101"
End Sub

Sub UnhideCenterSLcolumns()

Dim wsInput As Worksheet
Set wsInput = Sheet4
wsInput.Select
ActiveSheet.Unprotect Password:="cfs101"
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Columns("F:AK").Select
Selection.EntireColumn.Hidden = False

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
ActiveSheet.Protect Password:="cfs101"
End Sub

One is to hide the columns on one tab but like it to work on the followwing sheetss4,5,6,7,8,11

and the other tab is to unhide those columns on those same tabss.

Any suggestions????

Explanation / Answer

Sub UnhideCenterColumns()
    Dim wsInput As Variant
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    For Each wsInput In Array(Sheet2, Sheet4)
        wsInput.Unprotect Password:="cfs101"
        wsInput.Range("F3:AK3").EntireColumn.Hidden = False
        wsInput.Protect Password:="cfs101"
    Next wsInput
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub