• Prevent Changing Sheets (Excel 2k)

    Author
    Topic
    #372636

    Good Morning,
    I have created a spreadsheet that on Sheet1 a user enters some data and then goes to Sheet2 and the customized document they need is there. I have Sheet1 protected with some conditional formatting to prevent them from entering invalid data, but is there a macro that will prevent them from going to sheet2 unless certain conditions are met, say A1 must equal “Yes” before they can change Sheets. When they switch back from Sheet2 to Sheet1 there is a macro that clears the input data on Sheet1 so they start with a clean page.
    Thanks in advance for any information you fine folks can give!
    David

    Viewing 2 reply threads
    Author
    Replies
    • #596211

      Hi David,
      Since you can disable macros which might bypass your selection validation, I would suggest having Sheet2 hidden to start with. You can then have a button on Sheet1 which runs a macro to check what data has been entered on sheet1 and, if it’s OK, unhide and activate sheet2.
      Hope that helps.

    • #596237

      Hi Rory,
      Thank you for your quick reply. I have no experience with macros, the macro I use in that program is one that one of the nice people in this lounge provided for me. If it’s not too much trouble could I impose upon you to provide me an example. From the way you described it, it sounds like it will work perfectly.
      Thanks again for all of your help.
      David

      • #596250

        Without knowing the exact details I can’t be too specific, but it would be something fairly simple like:
        If [A1] = “Yes” then
        sheets(“Sheet2”).Visible = true
        else
        msgbox “A1 must equal Yes for you to continue”
        end if

        once you’ve hidden sheet2. You can add more conditions as necessary.
        To add the command button to the sheet, choose View-Toolbars-Control Toolbox then select the command button icon and draw it wherever you want. Next select the View Code button on the toolbox and paste your code into the module that appears.
        Hope that helps though if you need more info please repost.

    • #596297

      You can use the Sheet Activate and Deactivate event routines to do what you want. Code like the following in the Deactivate event will prevent changing to another sheet if A1 is not “Yes”.

      Private Sub Worksheet_Deactivate()
          If Worksheets("Sheet1").Range("A1")  "Yes" Then
              Application.EnableEvents = False
              Worksheets("Sheet1").Activate
              Application.EnableEvents = True
              MsgBox "All data not entered.", vbExclamation + vbOKOnly
          End If
      End Sub
      

      You can put code in the Sheet activate event to clear out old data.

      • #596657

        Thank you very much for taking the time to reply to my post, it worked like a charm!!
        David

    Viewing 2 reply threads
    Reply To: Prevent Changing Sheets (Excel 2k)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: