+ Reply to Thread
Results 1 to 12 of 12

macro to delete rows with a range for values

  1. #1
    Registered User
    Join Date
    03-28-2009
    Location
    blue ridge
    MS-Off Ver
    Excel 2003
    Posts
    4

    macro to delete rows with a range for values

    I need some assistance with a simple macro. Im clueless when it comes to macros.

    Heres what I have:

    column "e" contains the year built for homes. Some of the fields contain "9999" or "0000" or blank. I need to delete these entire rows. If the year is between 1900 and 2020 I would consider it valid and keep the row.

    So I need a macro that says something like this:

    if column "e" is not between 1900 and 2020 delete the entire row.

    Thanks very much for your assistance!!!
    Last edited by poole; 03-28-2009 at 01:03 PM.

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

    Re: need help with simple macro

    Welcome to the forum.

    Please take a few minutes to read the forum rules about thread titles, and then edit yours accordingly.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-28-2009
    Location
    blue ridge
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: macro to delete rows with a range for values

    Changed title and read rules.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: macro to delete rows with a range for values

    Thanks for taking the time to read and comply with the rule .

    Try thus modified code from this website

    http://www.rondebruin.nl/delete.htm#AutoFilter

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: macro to delete rows with a range for values

    here u go

    Please Login or Register  to view this content.

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

    Re: macro to delete rows with a range for values

    Give this macro a whirl:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 03-28-2009 at 01:24 PM.
    _________________
    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!)

  7. #7
    Registered User
    Join Date
    03-28-2009
    Location
    blue ridge
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: macro to delete rows with a range for values

    Man...you people are awesome!!! Thanks for the help!!!

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: macro to delete rows with a range for values

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

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

    Re: macro to delete rows with a range for values

    Quote Originally Posted by Shijesh Kumar View Post
    Please Login or Register  to view this content.
    Shijesh, when the goal is the deletion of rows, you have to start at the bottom and work up. If you start at the top then stuff gets missed.

    If rows 11 and 12 would both fail and require deleting, deleting row 11 moves row 12 up to row 11 and then the "next" command moves to the new row 12...effectively missing the old row 12 because it's now on row 11.

    For deletions, start at the bottom.

  10. #10
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: macro to delete rows with a range for values

    For deletions, start at the bottom.
    In general but no need with the filter method and usually faster IMO

    VBA Noob

  11. #11
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717

    Re: macro to delete rows with a range for values

    opps You are right ... since I work with Oracle Database i have never knew this limitation in EXCEL...

    Thanks >> Learned something new today :-)

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    03-28-2009
    Location
    blue ridge
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: macro to delete rows with a range for values

    Macro worked great, but I have one more issue. Let me know if I need to start a new thread.....new at this.

    I am referencing my data on another worksheet using something like this "=data!A2" when I initially put the data in the spreadsheet...it transfers just fine into the other worksheet. After I manipulate the data (run the macro), then switch over to the worksheet that references my data, some of the cells show up like this "=data!#REF!" Its like it loses the "A2"part.

    Any thoughts? Do I need to mark this thread as solved then start another?

    Thanks again!

+ 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