+ Reply to Thread
Results 1 to 4 of 4

Code deletes every other row but should delete every row

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Lightbulb Code deletes every other row but should delete every row

    I have code that is supposed to delete every row that contains a O in column T, but it is deleting every other row that contains a 0 in column T.

    Here is the code

    Please Login or Register  to view this content.
    i = 2 because the first row has headers and because I was getting a data type mismatch error.

    Any suggestions?

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Code deletes every other row but should delete every row

    You should step backward, since deleting row readjusts row index.

    Please Login or Register  to view this content.
    Edit: alternately you can loop to only increase count when row isn't deleted.
    Last edited by CK76; 04-06-2017 at 01:38 PM. Reason: See Edit:

  3. #3
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Code deletes every other row but should delete every row

    Of course! Thank you CK76!

    A followup Q - why is it better to use Rows(i)EntireRow.Delete instead of Rows(i).Delete?

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,913

    Re: Code deletes every other row but should delete every row

    Not much. EntireRow just allows you to use other range. Such as Cells, Range etc.

    Just force of habit that I used it

+ 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. Help with vba code that deletes all data except for highest value
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2014, 06:01 PM
  2. [SOLVED] For each x in y, delete row if match. Only deletes half of the matches?
    By thelisa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-17-2013, 05:11 PM
  3. Code deletes HEADER Row
    By rz6657 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2013, 01:43 PM
  4. [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
  5. Replies: 0
    Last Post: 01-06-2008, 01:23 PM
  6. Code that Deletes Itself
    By Caligula in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2007, 11:03 PM
  7. [SOLVED] My delete row button deletes only the cell not the row. Bug?
    By David4OHAN in forum Excel General
    Replies: 1
    Last Post: 07-10-2006, 09:04 PM

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