+ Reply to Thread
Results 1 to 20 of 20

Need VBA to delete cells based on criteria

  1. #1
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Need VBA to delete cells based on criteria

    I am trying to write a VBA (I am a beginner so it's very difficult....)

    I have an array of names in rTable A4 To B53 As Range. If a name changes to "VACANT" or "0" I want a subroutine to automatically delete the information from the corresponding row where the name once was.

    The information to be deleted is only contained within certain columns and cells (C4:C53, G4:G53, K4:R53).

    Any help is much appreciated!

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need VBA to delete cells based on criteria

    Do you want to delete the whole row? or just blank the columns you mentioned (in the affected row of course)? When you say a name changes to vacant or 0... does that mean either A or B changes? or are the names in column A only?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    I only want to delete the columns/cells mentioned. The names are listed in both Column A & B; last name, first name, repsectively, so both columns would change if a name ever changes. (last name would become "VACANT", first name would become "0")

    I don't know if this changes things, but I have the names linked to an outside workbook by HLOOKUP, hence the way they change. So the cells actually contain the formula but show the text.

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA to delete cells based on criteria

    See file attached with macro in sheet's code
    Attached Files Attached Files
    - Battle without fear gives no glory - Just try

  5. #5
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    @PCI: when I try to open your doc it says parts were removed/repaired, and I try to view the code and there is nothing there....

    Could be an issue with my security settings on this computer...I am at work :/

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA to delete cells based on criteria

    Try again, perhaps there was some conflict to access the file
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    @PCI: I entered this code and I thought I ran it correctly, but nothing worked...

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA to delete cells based on criteria

    See my file attached. Is it working ?
    Else send a sample of your file to install the macro
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    I'm afraid it didn't work and I am unable to get the attachments to upload


    Sorry... But thanks for the attempts to help!

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need VBA to delete cells based on criteria

    You put the code in the worksheet, not a normal module right?

  11. #11
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    I right click on Sheet 1 (which is where I want the code to run) and when I click view code, it is there. Maybe I'm not running it correctly?

  12. #12
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA to delete cells based on criteria

    Have a look in the file sent, how is it?

  13. #13
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    copied and pasted exact.

  14. #14
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need VBA to delete cells based on criteria

    maybe something failed earlier and enableevents is set to false?

  15. #15
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    "Application.EnableEvents = False" on the first line and 'True' on the second

  16. #16
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Need VBA to delete cells based on criteria

    I just meant if it gets stuck on false somewhere, then the change event won't trigger until you set it to true again with some vba code. I've had that happen, I make a quick sub called test or something with just application.enableevents = true, run it and then all is well again.

  17. #17
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    As a beginner (and I mean this is my very first time using it) to VBA I'm not sure I'm quite adept enough yet to know where it's getting stuck and re-write the code on my own....

  18. #18
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA to delete cells based on criteria

    Did you play with the file sent, is it working?
    With your file
    Before all treatments launch next macro to enable event
    Macro to be put in a module
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    04-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Need VBA to delete cells based on criteria

    Ok, if I place that code in a Module, when I go to run it, it pops up an error that says " argument not optional"

    When the code was NOT in a module, just in "Sheet 1 (code)" I couldn't even find the code anywhere when I would go to run it. (Developer tab, Macro button....nothing showed up listed anywhere; I'd try to type in what I thought it was named and nothing.)

  20. #20
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA to delete cells based on criteria

    The last code must be put in a module
    See file attached
    Attached Files Attached Files

+ 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 cells based on other cell criteria
    By ajob in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-28-2015, 06:17 AM
  2. [SOLVED] Run / loop through cells and delete based on criteria
    By Coeus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-16-2014, 04:37 PM
  3. VBA to delete a range of cells based on 1 criteria
    By Jim885 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2013, 08:52 AM
  4. Delete and shift cells up based on worksheet change and other criteria
    By beat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-25-2012, 05:22 PM
  5. Delete cells based on criteria
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2010, 02:26 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