+ Reply to Thread
Results 1 to 8 of 8

Dynamic Data Protection

  1. #1
    Registered User
    Join Date
    11-02-2006
    Posts
    11

    Dynamic Data Protection

    Hi all

    In order to protect a spread-sheet from accidental alteration of existing data - I felt it would be ideal to protect the new data that has been inputted (like a dynamic protection of data so to speak)?

    So if I enter something this week, I will not be able to make changes (whether accidental or not) to previous data i.e including that entered last week.

    This way, it is safer and I also have a backup of the excel sheet each time it is closed plus it is automatically saved (without user intervention).

    Any ideas on dynamic protection anyone? Thanks

    Usman
    Last edited by VBA Noob; 09-07-2008 at 08:06 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Why not use Worksheet Protection, and ensure the changes you make have their cells automatically locked. You could achieve this with a VBA macro attached to the WorkBook Save event.

    You'll need to work out how you define data that you have entered 'this week'. Is this data all in one column with a date label heading up the column for instance?

    So the general approach would be to first format all cells as Unlocked and then switch on Worksheet protection.

    Now in the Workbook Save event, have a line of code which identifies say the column of data you have just entered, (or the range of several columns if applicable) and which then locks all the cells in that column/range. The next time the workbook is opened you won't be able to overtype data in that column unless you were to manually unlock them.

    HTH

  3. #3
    Registered User
    Join Date
    11-02-2006
    Posts
    11

    Cell Protection/unlocking/locking

    Thats a good idea...

    Do you have a sample code for this as it will be very useful?

    Thanks

    Usman

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    See the attached.

    At the moment columns D:K are all unlocked cells and Sheet1 is protected. Whenever you enter an x in D1:K1 and save the workbook, the column containing the x will have its cells locked.

    This is only an example. You may want to detect which columns to protect by referring to a date, and testing that within the macro.

    The macro is in the Before_Save event of Sheet1 - right click on the sheet tab and click View code to see it.

    HTH
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-02-2006
    Posts
    11

    Question My Data

    Hi Richard

    Thanks for your message.

    I tried your macro - and found that once I typed the new entry, it locked the entire sheet on Save.

    I have attached some example data and would be grateful if you could sample that for the cell protection.

    Thanks in advance

    Usman
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-02-2006
    Posts
    11

    Solution

    Dear all,

    Solution follows to the above problem:
    ___________
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Sheets("SRD_V099994").Protect Password:="test", UserInterfaceOnly:=True
    Sheets("SRD_V099994").Cells.Locked = True

    If Sheets("SRD_V099994").Cells(ActiveCell.Row, ActiveCell.Column).Value = vbNullString Then Sheets("SRD_V099994").Cells(ActiveCell.Row, ActiveCell.Column).Locked = False

    End Sub
    ______________

    Hope this helps

    Usman

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    uzymedphys,

    Please read the Forum Rules and then edit your post to wrap your code with Code Tags.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    That's what the macro is designed to do - at least with Sheet1. You don't say exactly how you intend to use your MyData sheet. I did say it was an example and that you'd need to decide how you intend to recognise which cells need protecting. You need to understand the logic and then apply it to your actual data. At the moment I don't know how you are using it.

    Did you work through the example I gave and the data I showed on Sheet1 and observe how after saving and re-opening the workbook you couldn't then overtype the data you'd entered in the column marked with an x?

    Rgds

+ 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. using a dynamic reference cell to copy a range of cells within a data table
    By mcash in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2010, 10:22 AM
  2. Macro or Formula to extract data
    By incognito in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2007, 11:28 PM
  3. Lookup / Dynamic sorting of data
    By csiunatc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-26-2007, 08:58 AM
  4. Unlinking Imported Data
    By Donquick in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-15-2007, 09:29 AM
  5. Concatenate from columns of dynamic data
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2006, 05:28 AM

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