+ Reply to Thread
Results 1 to 7 of 7

Macro to delete contents of cells if user delete contents of other cells

  1. #1
    Registered User
    Join Date
    02-25-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    62

    Macro to delete contents of cells if user delete contents of other cells

    Hi there
    The following event procedure macro copies formulas from d5 and i5:n5 to a particular row below if text is entered into any of the columns e:g in that row. I want to adjust it (see comments I have added to it) so that it deletes the formulas in columns d and i:n in a particular row that is below row 5, if cells in columns e:g in that particular row are cleared. So it’s kind of the reverse. i put some comments in to try to demonstrate what I am trying to do.

    Please Login or Register  to view this content.
    Last edited by Stuartzz; 05-22-2018 at 09:19 PM. Reason: added code tags

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Macro to delete contents of cells if user delete contents of other cells

    Please edit your question and wrap your code in code tags.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro to delete contents of cells if user delete contents of other cells

    Works fine for me.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    02-25-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    62

    Re: Macro to delete contents of cells if user delete contents of other cells

    Thanks bakerman for doing that. I combined the 2 parts so that if you:
    - add text to 1 of the cells in question then formulas are copied into the row, and
    - if you delete text from one of the cells in question then formulas are deleted from the row.

    But I would like it so that formulas from the row are only deleted if there is no text in all of the cells in question. Currently if there is text in 2 of the cells in question and you delete text from one of them, the formulas are automatically deleted. I would like it so that if you delete text from 1 of the cells in question, formulas are not deleted unless all of the cells in question are blank.

    To illustrate I attached a sample file. If you delete the contents of cell g13, I don't want formulas to be deleted because there is still text in f13. So I suppose I was hoping that if text is deleted from g13, that the macro then makes sure that the range e13:g13 is completely clear before deleting the formulas.

    Apologies for not being clear with my requirements and thanks for your assistance.


    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro to delete contents of cells if user delete contents of other cells

    Try this way then.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-25-2010
    Location
    Canberra, Australia
    MS-Off Ver
    Office 365
    Posts
    62

    Re: Macro to delete contents of cells if user delete contents of other cells

    Fantastic! Thank you very much.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro to delete contents of cells if user delete contents of other cells

    Glad to help and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Delete only some of a cells contents
    By Dendrinos2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-11-2014, 06:16 AM
  2. [SOLVED] Delete contents of blank cells
    By freud1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2012, 10:53 AM
  3. Delete Contents of Cells with 0
    By EJensen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2009, 05:10 PM
  4. Delete contents of cells
    By mikespeck in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-27-2006, 10:25 AM
  5. delete contents of visible cells only
    By michael.beckinsale in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-05-2006, 04:35 AM
  6. [SOLVED] Delete Contents of Cells
    By ir26121973 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-05-2006, 02:15 PM
  7. [SOLVED] Delete specific cells contents in a row with some locked cells in the same row
    By trussman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2005, 03:06 PM

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