+ Reply to Thread
Results 1 to 11 of 11

Stumped - Delete Row based on criteria

  1. #1
    Forum Contributor
    Join Date
    06-23-2014
    Location
    Dubbo, Australia
    MS-Off Ver
    EXCEL 2019
    Posts
    180

    Stumped - Delete Row based on criteria

    I am having a problem deleting any rows in a worksheet where the desired text to look for is "Inactive". The code below correctly identifies a row, changes the value in Columnb J to "Inactive", and then I want to delete that same row, but the second part of the code to delete the row isn't working!
    Please Login or Register  to view this content.
    Can anyone enlighten me where I might be going wrong?

    cheers
    Pete
    Pete
    Struggling Solutions Architect

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Stumped - Delete Row based on criteria

    When you say "isn't working" do you mean a VBA error or it doesn't delete the correct rows?

  3. #3
    Forum Contributor
    Join Date
    06-23-2014
    Location
    Dubbo, Australia
    MS-Off Ver
    EXCEL 2019
    Posts
    180

    Re: Stumped - Delete Row based on criteria

    it doesn't delete the row - there is only ever one row to delete...

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Stumped - Delete Row based on criteria

    What is in column J?

    Cells(i, 10) really can be "Cells(I, "J")

    Are you really looking in column J for "Inactive"? Are there spaces before or after "Inactive"?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Stumped - Delete Row based on criteria

    Did a dummy sheet to test the code. The For Loop works fine on my dummy sheet.

    Can you manually type in "Inactive" in column J of any row to test?

    Also, you placed the word "Inactive" in a sheet called 'TreatmentOrders'. Can you confirm that when you run this macro that the active sheet is in the same sheet 'TreatmentOrders'? I note you have referred to Cells without the sheet qualifier.

  6. #6
    Forum Contributor
    Join Date
    05-02-2015
    Location
    calgary alberta
    MS-Off Ver
    2012
    Posts
    205

    Re: Stumped - Delete Row based on criteria

    Try splitting the if and then statements into two seperate lines. See if it recognizes the "inactive cell" and jumps down to the delete line

  7. #7
    Forum Contributor
    Join Date
    06-23-2014
    Location
    Dubbo, Australia
    MS-Off Ver
    EXCEL 2019
    Posts
    180

    Re: Stumped - Delete Row based on criteria

    Hi Marvin,

    Yes, I am looking in column J for "Inactive", there are no leading or trailing spaces.
    The previous four lines of code write "Inactive" (no punctuation or anything) into column J on the correct row... that bit checks out fine.

  8. #8
    Forum Contributor
    Join Date
    06-23-2014
    Location
    Dubbo, Australia
    MS-Off Ver
    EXCEL 2019
    Posts
    180

    Re: Stumped - Delete Row based on criteria

    Hi queckbc

    Earlier in the code I have this as a qualifier
    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Stumped - Delete Row based on criteria

    In that case, remember to put the fullstop "." before the Cells

    I.e.

    Please Login or Register  to view this content.

  10. #10
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Stumped - Delete Row based on criteria

    Is your active/selected sheet (the one that is visible) your
    Sheets("TreatmentOrders")?

    You can make it active by using a
    Sheets("TreatmentOrders").Select just before your For..Next loop.

  11. #11
    Forum Contributor
    Join Date
    06-23-2014
    Location
    Dubbo, Australia
    MS-Off Ver
    EXCEL 2019
    Posts
    180

    Re: Stumped - Delete Row based on criteria

    Hello all,

    Finally made it work, with all your help! It's looking a bit of a mishmash but it's doing the job!
    thanks everybody for your input and knowledge!
    Please Login or Register  to view this content.

+ 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. Replies: 7
    Last Post: 06-30-2015, 03:39 PM
  2. Delete row based on certain criteria
    By yuenk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2015, 12:26 PM
  3. [SOLVED] delete row based on criteria - help!
    By pinky24 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-18-2014, 11:14 AM
  4. Delete Row based on Criteria!!
    By vignesh rocks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2012, 07:30 AM
  5. Delete row based on criteria
    By D_N_L in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2011, 10:00 AM
  6. delete based on criteria
    By numbersdntlie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2011, 09:53 AM
  7. delete row based on criteria
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-03-2010, 05:13 AM

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