Forum Discussion

INeedHelpSoon's avatar
INeedHelpSoon
Copper Contributor
Jul 26, 2022

Protect WorkSheet but change cell values via VB without password dialogue

I have a worksheet with macro control. Other than control, the whole sheet is "locked" and password protected. When clicking on the control, I want to change some values in the worksheet (via VB code) w/o the "supply password" dialogue box coming up - yet I don't want to put a line of code in the VB that "supplies" the password as that would make it to easy for users to view.

How can this be accomplished?

  • JKPieterse's avatar
    JKPieterse
    Silver Contributor
    You can't have VBA code unprotect a sheet without the PW dialog and at the same time without including the password. But you can protect the VBA project so others cannot see the password. Would that help?
      • JKPieterse's avatar
        JKPieterse
        Silver Contributor

        INeedHelpSoon Sure, something like:

        Sub ChangeSomething()
            ActiveSheet.Unprotect "PasswordGoesHere"
            Range("C3").Value = "Entry Into cell C3"
            ActiveSheet.Protect "PasswordGoesHere"
        End Sub

Resources