+ Reply to Thread
Results 1 to 15 of 15

Code needed to repopulate a cell if it's deleted and show a message box.

  1. #1
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Code needed to repopulate a cell if it's deleted and show a message box.

    Hi guys,

    I've got some code that populates a table with data from another table whenever a date is selected from a dropdown list (in cell B9).

    I'm trying to add some more functionality so that if someone deletes a cell in the first table, then it will repopulate it and throw a message box saying "Oi!, Stop it!" ... or something a bit more diplomatic :D I can't simply protect and lock the cells as I need to be able to click on a cell to get some other information and RAG status using active cell formula. The second table, which contains all the important formula is protected though.

    The sample code shows it working for a single cell, but I need to extend this to a range and it keeps falling over. Any ideas greatly appreciated.

    Cheers,

    Jed.


    Please Login or Register  to view this content.

    PolulateSummaryTable:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Try :

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Works like a charm.

    Just a couple of questions about how it works:

    What does this bit do:

    If Not Intersect(Range("A:CV"), Target) Is Nothing Then


    Also, I assume this bit:

    Target.Value = Target.Offset(58, 0).Value

    is simply the cell reference from the second table ie it's 58 rows below the copied cell.

    Cheers,

    Jed.

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    It says "If Not Intersect(Range("E6:Q20"), Target) Is Nothing Then"

    It means if the cell that's changed is not within range "E6:Q20" then it doesn't fire the code between the "IF / ENDIF" part.

    And yes, the target.value = Target.Offset(58, 0).value means that the cell value is put to the cell value 58 rows below it.

  5. #5
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Excellent, thanks for the explanation and the working code :D

  6. #6
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Ahhh, just noticed a problem. It's fine if I delete a cell, but doesn't work if I overtype with a different value :/ Any suggestions?

  7. #7
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Adjust as follows. Your first request was "when someone deletes the value", which is different from "changes" ;-)

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Aha ... you think that I know what I want... :p

    I've changed the code (below) but it seems to be constantly looping ie I can see the calculation message showing in the bottom left of the screen and it keeps flickering...


    Please Login or Register  to view this content.

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    that could would never run-can you paste the actual code?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  10. #10
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    From the Sheet:

    Please Login or Register  to view this content.

    From the Module:

    Please Login or Register  to view this content.

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    that still can't work-you're missing an end sub

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    by the way do you think that this line
    Please Login or Register  to view this content.
    checks if B9 was the changed cell? (it doesn't)

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    I reckon your code probably ought to be
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Where should the missing end sub go?

    EDIT: aha, posted just before your additional post
    Last edited by Jed Shields; 05-07-2013 at 11:57 AM.

  15. #15
    Registered User
    Join Date
    08-01-2011
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: Code needed to repopulate a cell if it's deleted and show a message box.

    Joseph, you are correct ... that code works perfectly. Cheers

+ 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