'authorguoqiang 'date2007-12-19 Sub doChangeExcel() Dim count count = Sheets.count Debug.Print count For i = 1 To count 'get the assigned sheet Sheets.Item(i).Select 'get the name of the sheet SheetName = ActiveSheet.Name protected = ActiveSheet.ProtectContents 'ptotected = True ActiveSheet.Select '--------------------------------------- 'if it is Trans_Xcpt sheet, then row 5 is autofilter If SheetName = "Trans_Xcpt" Then If protected = True Then ActiveSheet.Select ActiveSheet.Unprotect Rows("5:5").Select Selection.AutoFilter Else Rows("5:5").Select Selection.AutoFilter ActiveSheet.Protect End If '--------------------------------------- 'if it is MTD_IN sheet, then row 4 is autofilter ElseIf SheetName = "MTD_IN" Then If protected = True Then ActiveSheet.Select ActiveSheet.Unprotect Rows("4:4").Select Selection.AutoFilter Else Rows("4:4").Select Selection.AutoFilter ActiveSheet.Protect End If '--------------------------------------- 'if it is Net_Demand sheet, then row 4 is autofilter ElseIf SheetName = "Net_Demand" Then If protected = True Then ActiveSheet.Select ActiveSheet.Unprotect Rows("4:4").Select Selection.AutoFilter Else Rows("4:4").Select Selection.AutoFilter ActiveSheet.Protect End If '--------------------------------------- 'if it is A_Supply sheet, then row 4 is autofilter ElseIf SheetName = "A_Supply" Then If protected = True Then ActiveSheet.Select ActiveSheet.Unprotect Rows("4:4").Select Selection.AutoFilter Else Rows("4:4").Select Selection.AutoFilter ActiveSheet.Protect EndIf '--------------------------------------- 'if it is Special_Cell sheet, then row 4 is autofilter ElseIf SheetName = "Special_Cell" Then If protected = True Then ActiveSheet.Select ActiveSheet.Unprotect Rows("4:4").Select Selection.AutoFilter Else Rows("4:4").Select Selection.AutoFilter ActiveSheet.Protect End If '--------------------------------------- 'else, only protect or unprotect Else If protected = True Then ActiveSheet.Select ActiveSheet.Unprotect Else ActiveSheet.Select ActiveSheet.Protect End If End If Next i End Sub |