+ Reply to Thread
Results 1 to 5 of 5

VBA to set password based on cell value

  1. #1
    Registered User
    Join Date
    06-09-2022
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    2

    Question VBA to set password based on cell value

    Hello , I have a task which I have 0 Knowledge in and want some help.

    So the task is to make macro run if i change a value in a certain cell , ex; on a certain sheet named "config" I entered a value in a certain cell which is the password for all sheets, and the task is to make a macro whenever I change the value to a new one "which is basically the password" it does update the password for all sheets to this new value

    Any help is appreciated.

    Btw here is the code which he typed but yeah it isnt a code

    Dim oldValue As Variant
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    oldValue = Target.Value
    End Sub
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim newValue As Variant
    newValue = Target.Value


    If newValue <> OldValue





    unprotect sheet Januar2022 by oldBValue
    protect sheet Januar2022 by newBValue

    unprotect sheet Febraur by oldBValue
    protect sheet Febraur by newBValue

    unprotect sheet März by oldBValue
    protect sheet März by newBValue

    unprotect sheet April by oldBValue
    protect sheet April by newBValue

    unprotect sheet Mai by oldBValue
    protect sheet Mai by newBValue

    unprotect sheet Juni by oldBValue
    protect sheet Juni by newBValue

    unprotect sheet Juli by oldBValue
    protect sheet Juli by newBValue

    unprotect sheet August by oldBValue
    protect sheet August by newBValue

    unprotect sheet September by oldBValue
    protect sheet September by newBValue

    unprotect sheet Oktober by oldBValue
    protect sheet Oktober by newBValue

    unprotect sheet November by oldBValue
    protect sheet November by newBValue

    unprotect sheet Dezember by oldBValue
    protect sheet Dezember by newBValue

    End If


    End Sub

    Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)

    End Sub

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA to set password based on cell value

    1) Copy this code.
    2) Right-Click the sheet tab of the sheet where you want to store the password - that cell, at least, should not be locked or protected.
    3) Select "View Code"
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.
    6) Make changes as needed

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA to set password based on cell value

    Sorry - change "$A$10" tot he address of the cell you want to use....

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,222

    Re: VBA to set password based on cell value

    A slightly different solution, without using the SelectionChange event. To be able to change more than one cell at a time, you need to expand the code more.
    Please Login or Register  to view this content.
    The expected cell to change is B3. Region-sensitive code. In DE it will return German month names, but in Poland they will be in Polish and in the US in English.

    Artik

  5. #5
    Valued Forum Contributor
    Join Date
    05-03-2022
    Location
    Halifax,Canada
    MS-Off Ver
    365
    Posts
    326

    Re: VBA to set password based on cell value

    SUGGESTION:
    Which ever macro you use you may like to add a confirmation message , at end of update, that indicates what sheets were updated.
    I'm thinking that each coding solution is going to have room for error considering use of wildCards etc ... so cofirming what has been changed might be a good idea.

    To do this ...
    (1) add the declaration : Dim shList As String
    (2) just after/below your sh.protect statement add : shList = shList & sh.Name & vbNewLine
    (3) Just above the "end sub" add the line of code : MsgBox shList, vbInformation, "Password Changes Made To ..."

    Attachment 783531
    msgBx.jpg

    FOR EXAMPLE ...

    Please Login or Register  to view this content.
    Last edited by nimrod1313; 06-10-2022 at 02:09 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. worksheet based on a password
    By tta.akmal in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-01-2018, 11:19 AM
  2. Replies: 2
    Last Post: 03-09-2015, 11:45 AM
  3. Display sheets based on password
    By CanadianGuy in forum Excel General
    Replies: 7
    Last Post: 08-22-2013, 03:32 PM
  4. [SOLVED] VBA to set password based on cell value
    By Ironman in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-20-2012, 07:23 PM
  5. [SOLVED] Macro to add password based on cell value
    By kevinarp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2012, 07:17 PM
  6. FIXED - MAcro to protect/unprotect sheets based on password in cell
    By pmcook1979 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-10-2012, 04:28 AM
  7. Replies: 0
    Last Post: 04-26-2006, 10:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1