Results 1 to 20 of 34

Thread: Two macro button but in a double action

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #19
    VBAX Tutor
    Joined
    Sep 2012
    Location
    London
    Posts
    286
    Location
    SamT hello
    I do not understand macros from clear to 1000%, in that there is absolutely no question but surely I do not understand or do not see - in your macro is incredibly made​​, but I can not see inside him where to enter the password (see himself that I was mistaken, that ThePassWord a password that it was not so).
    It is true that I did the most stupid way that may exist, but in post number 9 each sheet where I hide rows then I locked him sheets.
    And then when I open the workbook (again by button) unlock sheets and unhide rows show.
    Maybe you missed it, no big trouble.
    Let us alive and healthy.
    Regards



    Sub poslednaproba()
        Application.ScreenUpdating = False 
        If Range("4:4").EntireRow.Hidden = False Then 'Sub hide
            Sheets(Array("London", "Italy", "Paris", "UK", "Greece")).Select 
            Sheets("London").Activate 
            Rows("2:2").Select 
            Selection.Locked = False 
            Selection.FormulaHidden = False 
            Range("4:4,5:5,10:10,11:11,13:13,14:14,17:17,18:18,34:34,35:35,38:38,45:45,46:46,49:49,50:50,72:72,73:73,76:76,77:77,78:78,79:79").Select 
            Range("A79").Activate 
            Selection.EntireRow.Hidden = True 
            Range("A2").Select 
            Sheets("London").Select 
            ActiveSheet.Protect ("kosta"), ' Please look at these lines, see how I put a password on the sheets - here we do not do something in your macroDrawingObjects:=True, Contents:=True, Scenarios:=True _ 
            , AllowFiltering:=True 
            Sheets("Italy").Select 
            ActiveSheet.Protect ("kosta"), ' Please look at these lines, see how I put a password on the sheets - here we do not do something in your macroDrawingObjects:=True, Contents:=True, Scenarios:=True _ 
            , AllowSorting:=True, AllowFiltering:=True 
            Sheets("Paris").Select 
            ActiveSheet.Protect ("kosta"), ' Please look at these lines, see how I put a password on the sheets - here we do not do something in your macroDrawingObjects:=True, Contents:=True, Scenarios:=True _ 
            , AllowSorting:=True, AllowFiltering:=True 
            Sheets("UK").Select 
            ActiveSheet.Protect ("kosta") 'Please look at these lines, see how I put a password on the sheets - here we do not do something in your macro, DrawingObjects:=True, Contents:=True, Scenarios:=True _ 
            , AllowSorting:=True, AllowFiltering:=True 
            Sheets("Greece").Select 
            ActiveSheet.Protect ("kosta") 'Please look at these lines, see how I put a password on the sheets - here we do not do something in your macro, DrawingObjects:=True, Contents:=True, Scenarios:=True _ 
            , AllowSorting:=True, AllowFiltering:=True 
            Sheets("London").Select 
            Range("A2").Select 
            Application.ScreenUpdating = True 
        Else 
            On Error Goto ErrHandler 
            Range("A2").Select 
            Sheets("London").Select 
            ActiveSheet.Unprotect Password:=InputBox("Please write your password!") 
            Cells.Select 
            Selection.EntireRow.Hidden = False 
            Range("A1").Select 
            Exit Sub 
    ErrHandler: 
            MsgBox "Wrong password", vbExclamation 
             
            Application.ScreenUpdating = True 
             
            Sheets("Italy").Select 'and here again foolishly trying to unlock and show rows
            ActiveSheet.Unprotect Password:=InputBox("Please write your password!") 
            Cells.Select 
            Selection.EntireRow.Hidden = False 
            Range("A1").Select 
            Exit Sub 
    ErrHandler: 
            MsgBox "Wrong password", vbExclamation 
            Sheets("Paris").Select 'and here again foolishly trying to unlock and show rows
            ActiveSheet.Unprotect Password:=InputBox("Please write your password!") 
            Cells.Select 
            Selection.EntireRow.Hidden = False 
            Range("A1").Select 
            Exit Sub 
    ErrHandler: 
            MsgBox "Wrong password", vbExclamation 
            Sheets("UK").Select 'and here again foolishly trying to unlock and show rows
            ActiveSheet.Unprotect Password:=InputBox("Please write your password!") 
            Cells.Select 
            Selection.EntireRow.Hidden = False 
            Range("A1").Select 
            Exit Sub 
    ErrHandler: 
            MsgBox "Wrong password", vbExclamation 
            Sheets("Greece").Select 'and here again foolishly trying to unlock and show rows
            ActiveSheet.Unprotect Password:=InputBox("Please write your password!") 
            Cells.Select 
            Selection.EntireRow.Hidden = False 
            Range("A1").Select 
            Exit Sub 
    ErrHandler: 
            MsgBox "Wrong password", vbExclamation 
            Sheets("London").Select 
            Range("A2").Select 
        End If 
    End Sub


    Sub poslednaproba() 
        Dim RowsToHide As String 
        Dim SheetsToUse As Variant 
        Dim TestSheet As String 
        Dim ThePassWord As String 
        Dim Result As Long 'Add This declaration
        Dim i As Long 
         
        RowsToHide = "4:5, 10:11, 13:14, 17:18, 34:35, 38:38, 45:46, 49:50, 72:73, 76:79" 
        SheetsToUse = Array("London", "Italy", "Paris", "UK", "Greece") 
        TestSheet = "London" 
         
        Application.ScreenUpdating = False 
         
         'Add the following code ->>> please tell me which code might add here?
        Result = MsgBox(Click YES To toggle this sheet. Click NO To toggle all sheets. Click CANCEL To cancel action", vbYesNoCancel) 
        Select Case Result 
        Case vbOK 
            SheetsToUse = Array(ActiveSheet.Name) 
            TestSheet = SheetsToUse(LBound(SheetsToUse)) 
        Case vbCancel 
            Exit Sub 
        End Select 
         'End Add Code Section ->>>>please tell me which code might add here?
         
        ThePassWord = InputBox("Please write your password!")

    Last edited by k0st4din; 09-15-2014 at 10:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •