+ Reply to Thread
Results 1 to 8 of 8

Help to modify Macro - delete rows that DO NOT contain a negative number.

  1. #1
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    Help to modify Macro - delete rows that DO NOT contain a negative number.

    Hello Everyone,

    I am looking for some help with modifying a Macro I have:

    This Macro deletes all rows that DO NOT contain the numbers 0, 1, 2, 3, 4 and 5 in column D.

    I would like it if it ALSO DID NOT delete the rows containing a negative number in column D.
    (The negative numbers can go from -1 to -160).

    I am not sure how I can add this to the array.
    I have tried adding "<>*-*" or "<0" to the array but this does not work … 


    Any help would be very much appreciated!
    Thanks in advance!


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Help to modify Macro - delete rows that DO NOT contain a negative number.

    can you attach a sample file with data and desired result ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Help to modify Macro - delete rows that DO NOT contain a negative number.

    Hi, chicalaeti,

    AFAIK you would need to use a formula for a different column and evaluate that on using the Autofilter. I´d suggest you consider to use the Advanced Filter instead for trimming the set to suit.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Help to modify Macro - delete rows that DO NOT contain a negative number.

    Sure!

    I have attached an Excel file with a very small sample.
    The table on the left is the raw data.
    The table on the right is what I would like to end up with.

    The rows where the numbers 6,7,8,18,27 and 45 appear in column D were deleted.
    And we are left with only the rows that contain the numbers 0,1,2,3,4,5 or a negative number in column D.

    The numbers in column D change every day. SAMPLE.xlsx


    Thank you!!

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Help to modify Macro - delete rows that DO NOT contain a negative number.

    Try the attached.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Help to modify Macro - delete rows that DO NOT contain a negative number.

    Hi HaHoBe!

    Thank you for your answer!

    I would rather keep it in Macro form though as this Macro is right in the middle of a larger Macro that does a bunch more things with the data.

    I do appreciate the suggestion!

  7. #7
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Help to modify Macro - delete rows that DO NOT contain a negative number.

    AB33 !!

    That works perfect!
    Thank you very much!

    And thanks to all of you for taking the time to write back!

  8. #8
    Registered User
    Join Date
    11-11-2013
    Location
    Mexico City, Mexico
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Help to modify Macro - delete rows that DO NOT contain a negative number.

    You have been very very helpful already but I am hoping that perhaps someone could help me with one more thing...

    I have a different file where I am again using the same Macro as before. The difference in this file is that:

    Instead of having a minus sign in front of the number to show a negative, the number is put between paratheses.
    Like (1) (6) (18) etc...

    I would like to see if it is posible to have a similar Macro as above that would keep all the numbers from 0 to 5 AS WELL as the ones in paratheses this time. (those number are also red - if that helps)

    I have attached a sample of the new file and I would be eternally gratefull if anyone has any suggestions.


    SAMPLE 2.xlsx


    The table on the left is the raw data and the table on the right is the result I would like
    As you can see in the sample, only the rows where the numbers 1,2,3,4,5 and(1),(6),(39) are present in column F remain and the rest
    are deleted.

    Again thank you!

+ 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. [SOLVED] Modify Macro to insert/delete rows based on cell value
    By Marvelous in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-05-2013, 10:49 AM
  2. Delete rows based on lower value than number specified , positive or negative values
    By LadyNicole in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 06-11-2013, 03:33 AM
  3. [SOLVED] Macro to delete rows with zero in column deletes row that contain 0 in any number
    By Bjordion in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2012, 02:55 AM
  4. [SOLVED] Modify formula based on first non-negative number in a row
    By DrSues02 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-09-2012, 08:40 PM
  5. Delete rows without numbers (modify existing script)
    By The Phil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2011, 11:13 AM

Tags for this Thread

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