+ Reply to Thread
Results 1 to 5 of 5

my code delete all the rows

  1. #1
    Registered User
    Join Date
    05-13-2011
    Location
    Egypt
    MS-Off Ver
    Excel 2003
    Posts
    49

    my code delete all the rows

    here is my code for cut a row upon value of specific cell then paste it in other sheet then delete the cutted row but when it execute it delete all the rows not the cutted one only

    Please Login or Register  to view this content.
    Last edited by suny100; 05-17-2011 at 02:36 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: my code delete all the rows

    Try this instead:

    Please Login or Register  to view this content.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    05-13-2011
    Location
    Egypt
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: my code delete all the rows

    Quote Originally Posted by davegugg View Post
    Try this instead:

    Please Login or Register  to view this content.
    thanks a lot , of course it worked well
    but asn iam new in vba could i know where was the error in my code as it worked with other sheet and other criteria???

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: my code delete all the rows

    There were a couple possible problems with your code. It didn't specify which sheet it was working on, so lines such as your fourth one could be running on either sheet. But then you activate sheet1, so now the code is working on sheet 1 when you wanted it to loop through sheet 2. Additionally, when you delete a row, the row directly ahead of it takes its place. So if you had an 11 on row 20, what used to be on row 21 will be moved to row 20 after you delete the old row 20. However, your counter "my" goes to 21, so the data that used to be on 21 will get skipped. If you step through your old code and you have 11 on two consecutive lines, you will notice only one of them get moved.

  5. #5
    Registered User
    Join Date
    05-13-2011
    Location
    Egypt
    MS-Off Ver
    Excel 2003
    Posts
    49

    Re: my code delete all the rows

    Quote Originally Posted by davegugg View Post
    There were a couple possible problems with your code. It didn't specify which sheet it was working on, so lines such as your fourth one could be running on either sheet. But then you activate sheet1, so now the code is working on sheet 1 when you wanted it to loop through sheet 2. Additionally, when you delete a row, the row directly ahead of it takes its place. So if you had an 11 on row 20, what used to be on row 21 will be moved to row 20 after you delete the old row 20. However, your counter "my" goes to 21, so the data that used to be on 21 will get skipped. If you step through your old code and you have 11 on two consecutive lines, you will notice only one of them get moved.
    Really, thank you for your precious help

+ 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