+ Reply to Thread
Results 1 to 14 of 14

VB Code - Cell(Lx)= (x) then delete row (x)

  1. #1
    Forum Contributor
    Join Date
    08-06-2007
    Posts
    105

    VB Code - Cell(Lx)= (x) then delete row (x)

    Can anyone help me here? I'm in need of a VB Code.

    I need the code to do the following:

    If any cell in column "L" = "n/a" then delete that corresponding row.

    IE - Cell L23 = n/a so then delete row 23.

    Thanks in advance!
    Last edited by adgjqetuo; 05-12-2009 at 02:02 PM.

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

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Give this a try:
    Please Login or Register  to view this content.
    _________________
    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
    Administrator JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Hmm...you could also do it with an AutoFilter. This does the deleting of rows in one step...definitely faster.
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 05-12-2009 at 12:37 PM.

  4. #4
    Forum Contributor
    Join Date
    08-06-2007
    Posts
    105

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Thanks for the help!

    I tried both, and I'm getting a "complile error" for option explicit

    Please Login or Register  to view this content.
    I got the same error for both codes you provided. any ideas?
    Last edited by adgjqetuo; 05-12-2009 at 01:42 PM.

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

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Hah...That goes ABOVE the macros. Sorry about that.

    Please Login or Register  to view this content.
    When inserting code provided by others into other macros or commandbuttons, only insert the code between the SUB/END SUB lines

  6. #6
    Forum Contributor
    Join Date
    08-06-2007
    Posts
    105

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Still got the error - but when i deleted "option explicid" it worked perfectly!!

    Thank you SOOO MUCH!!!

  7. #7
    Registered User
    Join Date
    06-23-2009
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Hey guys, is there a way to do the opposite of this.

    Example. - if "l2" doesnt exist , delete row ?

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

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    That doesn't make sense, sorry. How are you asking to evaluate the cell? if I2 is blank? Or empty? Then delete row2?

  9. #9
    Registered User
    Join Date
    06-23-2009
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    sorry mate - my mistake.

    I was hoping to do a DELETE ROW if multiple values do NOT exist.
    The value can be into the thousands - because i only need the results which include 25 values.

    It might be possible to get a script to run through the sheet and delete and row , if it does not contain one of my 25 value's.

    So it would be a ARRAY ??

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

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Yes, you can loop through a dataset and compare a cell's value to a list and delete the row if it does not match any of your values.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-23-2009
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    oh mate, thats excellent.

    is there any chance you could explain how this line works

    Case "Dog", "Cat", 10 to 20, 99, "Bird"

    I was hoping to use something like this first - so i can easily modify it later to suit.

    vlist = array("test01", "Test07", "Test21", "Test94")
    case = vlist


    ????

  12. #12
    Registered User
    Join Date
    06-23-2009
    Location
    NSW, Australia
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Got it sorted. Thankyou very much mate. sorry to hijack the thread

  13. #13
    Registered User
    Join Date
    02-12-2011
    Location
    liverpool england
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    Hi guys,

    How could I smilarly do the following;
    where their are 4 text values which could match multiple numbers .eg a row is completely deleted if one of the numbers matches one of the 4 text values on the same row.

    thanking in advance

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

    Re: VB Code - Cell(Lx)= (x) then delete row (x)

    The code in post 10 showed how to LEAVE the rows alone if they matched specific things, and delete the rest. You can use the same code but put the "delete" code into the section that is matching the text strings.

+ 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