+ Reply to Thread
Results 1 to 13 of 13

Delete cell values based off of specified cell values

  1. #1
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Question Delete cell values based off of specified cell values

    If I have a row of data and a cell that contains a few specific values in cell I10 (such as 'yes' 'no' 'maybe'), am I able to set something up so data in other cells (in the same row) is removed IF 'maybe' is the value in I10? Cells J10 and O10

    Thanks for taking a look!

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Delete cell values based off of specified cell values

    Hello
    Assuming you wish to look down column 'I' and clear columns 'J' and 'O' on each row where column 'I' is equal to 'Maybe', then try something like:

    Please Login or Register  to view this content.
    This loops down to row I20 but can be made variable.

    DBY

  3. #3
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Delete cell values based off of specified cell values

    This would have to be attached to a button or something right? It wouldn't do it automatically, as soon as the 'i' cell is changed to 'maybe'? Would what I'm describing be able to be done with conditional formatting?

    Quote Originally Posted by DBY View Post
    Hello
    Assuming you wish to look down column 'I' and clear columns 'J' and 'O' on each row where column 'I' is equal to 'Maybe', then try something like:

    Please Login or Register  to view this content.
    This loops down to row I20 but can be made variable.

    DBY

  4. #4
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Delete cell values based off of specified cell values

    It could be triggered from a worksheet value change event for a particular column such as 'I'. Conditional formatting could only hide the values not delete them.

    The Worksheet Change Event code would be something like:

    Please Login or Register  to view this content.
    Last edited by DBY; 08-08-2016 at 03:28 PM. Reason: added code example

  5. #5
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Delete cell values based off of specified cell values

    Quote Originally Posted by DBY View Post
    It could be triggered from a worksheet value change event for a particular column such as 'I'. Conditional formatting could only hide the values not delete them.

    The Worksheet Change Event code would be something like:

    Please Login or Register  to view this content.
    Should/ would I have to do anything so it only targets one sheet/tab? Also, how would you add more than one value to trigger the clear event? Say the other value that triggers the clear even is "no".

    I tried using it. Couldn't get it to work... I don't need to use the code from post #2 in conjunction with your second post do I?
    PS. I changed my event clear values to "future" and "NIC"
    The cell which receives either of these values will already have a value in it if that changes anything.

    This is what I tried
    Please Login or Register  to view this content.
    Last edited by Clarkit; 08-09-2016 at 12:12 PM.

  6. #6
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Delete cell values based off of specified cell values

    It will only work within the Sheet the Event is placed in, so if you've selected Sheet 1 for the value change event then that's the sheet in which it's triggered. It's triggered when the any of the designated cell's values are changed, so if they have values in there it shouldn't make any difference. The following code should work with either: "NIC" or "Future".

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Delete cell values based off of specified cell values

    Quote Originally Posted by DBY View Post
    It will only work within the Sheet the Event is placed in, so if you've selected Sheet 1 for the value change event then that's the sheet in which it's triggered. It's triggered when the any of the designated cell's values are changed, so if they have values in there it shouldn't make any difference. The following code should work with either: "NIC" or "Future".

    Please Login or Register  to view this content.
    That works, thanks for your help!
    Side note, I noticed you're unable to 'undo' 'control+z'
    Is that just the nature of the beast?

  8. #8
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Delete cell values based off of specified cell values

    Yes, unfortunately with VBA, Undo is not available to fall back on, so it's good to have regular backups of your file. You can put a check in before deletion but once it's gone it's gone. Glad to have helped.

    Thanks for the Rep mark.

    DBY

  9. #9
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Delete cell values based off of specified cell values

    Quote Originally Posted by DBY View Post
    Yes, unfortunately with VBA, Undo is not available to fall back on, so it's good to have regular backups of your file. You can put a check in before deletion but once it's gone it's gone. Glad to have helped.

    Thanks for the Rep mark.

    DBY
    A few follow up questions now that I have been able to test it out for a few days.
    If I mark an item 'NIC' (by typing) it works great
    If I mark an item 'NIC' (by typing) and then highlight that cell to drag down the contents of that cell (lower right hand corner of cell) to the next line (to avoid typing NIC multiple times) it won't delete the cells if you copy it down to more than 1 row below the item.(why?)
    Also if you 'ctrl+c and ctrl+v' 'NIC' to another cell, it also doesn't delete the specified cells.(why?)

    Separate 'issue'- not really part of the original question, but if I wanted to have ANY cell that contains 'Future' or 'NIC' already to have the specified cells deleted (basically no worksheet change event). What would you do?
    Data gets copied from one worksheet to another (so many lines may already have the keywords that trigger cells to delete)

    Thanks!

  10. #10
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Delete cell values based off of specified cell values

    Hi
    I can't stay at the PC long at the moment but copy and paste will not trigger the Change Event unfortunately. If you wish to copy across and then delete those cells, you could do that with a simple loop code. I'll post an example tomorrow if that would help.

    DBY

  11. #11
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Delete cell values based off of specified cell values

    Separate 'issue'- not really part of the original question, but if I wanted to have ANY cell that contains 'Future' or 'NIC' already to have the specified cells deleted (basically no worksheet change event). What would you do?
    Data gets copied from one worksheet to another (so many lines may already have the keywords that trigger cells to delete)
    Here is an example file of a loop. It loops through I10:I3500 looking for 'NIC' or 'Future' (not case specific). For each row it finds either value it clears contents of adjacent columns 'J' and 'O'.

    Perhaps this would be a better solution for you.

    DBY
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    12-24-2013
    Location
    lancaster, pa
    MS-Off Ver
    Excel 2003
    Posts
    74

    Re: Delete cell values based off of specified cell values

    Quote Originally Posted by DBY View Post
    Here is an example file of a loop. It loops through I10:I3500 looking for 'NIC' or 'Future' (not case specific). For each row it finds either value it clears contents of adjacent columns 'J' and 'O'.

    Perhaps this would be a better solution for you.

    DBY
    Works well, Could a worksheet change even trigger this for me?

  13. #13
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Delete cell values based off of specified cell values

    Yes it can be triggered by a Worksheet Change Event. You would need to decide what event to use.

+ 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. Help Needed to Delete Rows Based On Cell Values
    By Jbracknell in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2015, 09:17 PM
  2. [SOLVED] Delete entire row based on multiple cell values
    By The Phil in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-08-2015, 09:43 PM
  3. [SOLVED] How to delete adjacent cells values based on one cell?
    By meprad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-31-2013, 09:07 AM
  4. [SOLVED] Sort and delete rows based on the values in a cell?
    By thup_98 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2013, 09:45 AM
  5. delete rows based on multiple cell values
    By Eddie2012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2012, 12:04 PM
  6. How to delete rows of data based on cell values in VB?
    By drx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2011, 04:45 PM
  7. Delete rows based on values in another cell
    By jimboc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2007, 08:54 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