+ Reply to Thread
Results 1 to 8 of 8

Delete Rows Multiple Criteria w/Numbers

  1. #1
    Registered User
    Join Date
    12-05-2007
    Location
    Oklahoma
    MS-Off Ver
    2003, 2007
    Posts
    22

    Delete Rows Multiple Criteria w/Numbers

    I am trying to use the code below to eliminate data in a spreadsheet based on certain criteria. I have been able to get this to work with text fields just fine, but now I am running into an issue with numbers. I am trying to get this code to delete rows if they have the word "unknown" in column C and if the value in column B is greater than 900 hours (999:00:00), the numbers in this column are formatted as [hhh]:mm:ss. What should I tweak to make this work?

    Please Login or Register  to view this content.
    Last edited by eriknokc; 12-23-2009 at 07:26 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Delete Rows Multiple Criteria w/Numbers

    Hi,

    1. Have you set the variable Last_Row somewhere?
    2. Take out the double quotes around the 900.

    However I can't help thinking that you'd be better filtering the data and then deleting the filtered rows rather than doing this with a loop. Loops are fine if the data set is relatively small, but with larger data sets you'll find they are much slower than using in built Excel functions such as data filter.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    12-05-2007
    Location
    Oklahoma
    MS-Off Ver
    2003, 2007
    Posts
    22

    Re: Delete Rows Multiple Criteria w/Numbers

    Yes, I forgot that part. I do have the last row set as below. I have tried removing the double quotes, but that does not work.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,947

    Re: Delete Rows Multiple Criteria w/Numbers

    Your code,
    Please Login or Register  to view this content.
    indicates that the values in column B are all text values. Is this the case, or do the cells contain numbers for calculations? If these are meant to be numbers and not text strings then the quotes must be deleted ( 900 is not "900"):

    Please Login or Register  to view this content.
    Also, I'm not sure from your description whether both conditions must be true or if you want the row deleted if either is true. Do you want the row deleted if either B is greater than 900 OR C is Unknown?
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    12-05-2007
    Location
    Oklahoma
    MS-Off Ver
    2003, 2007
    Posts
    22

    Re: Delete Rows Multiple Criteria w/Numbers

    Sorry about not being clearer on that. I was looking for it to require meet both conditions in order for it delete the row.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Delete Rows Multiple Criteria w/Numbers

    Try this:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    12-05-2007
    Location
    Oklahoma
    MS-Off Ver
    2003, 2007
    Posts
    22

    Re: Delete Rows Multiple Criteria w/Numbers

    shg Forum Guru, that worked perfect! Thanks everyone for your help and insight into this.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Delete Rows Multiple Criteria w/Numbers

    You're welcome.

    I agree with Richard's comment, BTW.

+ 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