+ Reply to Thread
Results 1 to 9 of 9

Delete Range by Cells

  1. #1
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Delete Range by Cells

    I'm probably gunna have to slap myself, but why doesn't this work?

    Please Login or Register  to view this content.
    I threw this in:

    Please Login or Register  to view this content.
    And it accurately tells me which values of X need deleting. So I assumed that there is something wrong with the statement:

    Please Login or Register  to view this content.
    However, when I threw the original in it's own sub it worked just fine.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete Range by Cells

    Hello magness,

    When deleting cells or rows, you should start at the bottom and go up. Like this...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete Range by Cells

    That gets rid of the need for "X = X - 1", however it still does not execute correctly as the end of the procedure.

    Interestingly, I had moved this its own sub in my testing module and did a call which worked. Prepared to just live with that I tried to move the sub into the same location as the original (on a sheet) and now get an error:

    Run-time error '1004':
    Application-defined or object-defined error

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete Range by Cells

    Hello magness,

    In the interest of time, post your workbook so I can review it and find the problem.

  5. #5
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete Range by Cells

    It is a big mess, but if you Find "CleanUp" on the Sets sheet that is where the issue is.

    Thanks

    Count Request Wizard v1.45.xls

  6. #6
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete Range by Cells

    I'm about to be out for the day so I won't get back here until tomorrow. Thank you for the help.

  7. #7
    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 Range by Cells

    Changing the loop control variable inside a loop is a cardinal sin.

    Please Login or Register  to view this content.
    Last edited by shg; 02-23-2010 at 01:31 PM.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Delete Range by Cells

    Hello magness,

    I made a few changes to the macro. The main problem was with Cells. When Cells does not have a qualifier, it refers to the cells on the active sheet. Here is an example.
    Please Login or Register  to view this content.
    You defined the variable "x" as an Integer. An integer will only allow you to access 32767 rows. To be able to access all rows on a worksheet, even a 2007 worksheet, "x" should be defined as Long. Here is the updated macro.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-08-2009
    Location
    Madison, WI
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Delete Range by Cells

    Changing the loop control variable inside a loop is a cardinal sin.
    Agree, that was pure idiocy on my part for a number of reasons.

    The main problem was with Cells.
    *headdesk*

    Yep, that would do it. Thank you.

    You defined the variable "x" as an Integer.
    Good point. I don't expect X to ever get that large, but it couldn't hurt to be covered.

    Thank you for taking a look at my mess. Posting the workbook felt a bit like showing folks my dirty room, but perhaps it will inspire me to clean up a bit.

+ 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