+ Reply to Thread
Results 1 to 9 of 9

Disabling Option to Delete using VB Code

  1. #1
    Registered User
    Join Date
    10-14-2009
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    43

    Disabling Option to Delete using VB Code

    I have three columns in an excel sheet.

    A B C
    Date Logged HRID Name

    This excel sheet has a timestamping VB code applied. (see below) How do I customize it in a way that details under column A will not be deleted manually? I tried password protect but I seem to get VB Code debug issues whenever I activate it.

    Please Login or Register  to view this content.
    Thank you.
    Attached Files Attached Files
    Last edited by ltmaiyk; 04-20-2010 at 09:52 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Disabling Option to Delete using VB Code

    EDIT: Please Edit your post above and put the code in code tags, like I do here:
    ---------------------

    1) Unlock the cells in columns B and C where the user will enter data.
    2) Protect the sheet with a password
    3) Use this in the sheet module:
    Please Login or Register  to view this content.

    Obviously you'll need to edit the second macro to have your password, and you may need to tweak the additional parameters so the sheet is protected with the features you want. I'm just showing you how to add the hidden parameter UserInterfaceOnly which allows macros to work on a protected sheet in protected cells even though the user can't.
    Last edited by JBeaucaire; 04-15-2010 at 10:20 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Disabling Option to Delete using VB Code

    Question about your macro's behavior...if someone deletes a value in column C, column B gets cleared, too. Is that right? Clear column B and leave column A?

    Also, do you really want a full timestamp? You can get just the date by changing Now() in the macro to Date.

  4. #4
    Registered User
    Join Date
    10-14-2009
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Disabling Option to Delete using VB Code

    Sorry but I am not really familiar with VB Codes (still studying). I only got this code from this forum.

    Any suggestion?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Disabling Option to Delete using VB Code

    Quote Originally Posted by ltmaiyk View Post
    Any suggestion?
    Um, yes. Did you not read my posts above?

    1) Edit your original post above, post #1, and add
    Please Login or Register  to view this content.
    [/noparse]
    tags around the code you posted, it will look like mine in post #2 when you do that.

    It is a forum rule, if you don't do it, this thread will get moderated and I won't be able to respond at all.

    2) I posted code for you to try in post #2.

    3) I asked you a couple of questions in post #3 about what you WANT to happen when data is manually cleared from column C. Please answer it. They are not macro questions.
    Last edited by JBeaucaire; 04-15-2010 at 11:14 AM.

  6. #6
    Registered User
    Join Date
    10-14-2009
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Disabling Option to Delete using VB Code

    1) I have already applied
    Please Login or Register  to view this content.
    as instructed.

    2) I copied/pasted the code you gave me and saved the xls file. When I re opened it, I had the debug pop-up prompt. When I clicked debug, VB Code appeared and "Cells (Target.Row, "a").Value = Now()" was highlighted.

    3) Column C must also be protected. Only editable column should be Column B, whereas, if data in that column is deleted, info under column A and C will be deleted too.

    As for Column A, I also wish that users will not be able to manually delete data in this column. As previously stated, it should only be deleted (automatic) if data in B has been deleted.

    Am I making any sense? Really sorry. Also, do you have any articles on simple VB Codes that I can read?

    Thank you so much!

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Disabling Option to Delete using VB Code

    You know, I just assumed, wrongly so, that you would know the Worksheet_Activate macro wouldn't allow you to edit the sheet until you changed to a different sheet then came back to it, thus "activating" that macro.

    Here, use this instead. Take out the Worksheet_Activate() macro completely. Then put this macro into the the ThisWorkbook module:

    Please Login or Register  to view this content.

    Be sure to edit that to the correct sheet name if it's not Sheet1. Then save and close your workbook. Now when you open it the flag will be set and your other macro will work.

    ========
    If column C is protected, too, why does your original macro check for column 2 or 3? Shouldn't it just check for column 2, column "B"?

  8. #8
    Registered User
    Join Date
    10-14-2009
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Disabling Option to Delete using VB Code

    Files works perfectly fine now. Thank you. Thank you. Thank you!

    You are also correct with Column C being protected. Thanks

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Disabling Option to Delete using VB Code

    If you really need to just watch column B and you don't want the macro to cause an error if you try to delete the contents of more than one cell at a time, use this instead:

    Please Login or Register  to view this content.

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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