+ Reply to Thread
Results 1 to 6 of 6

Macro to delete entire rows if column d equals 2925-6 & abc

  1. #1
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    134

    Macro to delete entire rows if column d equals 2925-6 & abc

    I received the following macro to delete rows if column D contains 2923-3, but when I run it, it deletes the first row, which is the column header.
    Sub Triscia()
    Range("D1:D" & Range("D" & Rows.Count).End(3).Row).AutoFilter 1, "2923-3", xlAnd, "other"
    Range("D1:D" & Range("D" & Rows.Count).End(3).Row).SpecialCells(12).EntireRow.Delete
    ActiveSheet.AutoFilterMode = False
    End Sub

    I have one macro that does about 10 different things, this is the 4 step that needs to be run. Can anyone assist me with this? My worksheet is call All POs back to 2.9.15 and I have each task ending with End With. TIA!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Macro to delete entire rows if column d equals 2925-6 & abc

    Have you tried changing D1 to D2 in the first two lines of code? Or, thinking about it, maybe just the second line. Try just the second line


    Regards, TMS
    Last edited by TMS; 05-14-2015 at 07:04 AM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: Macro to delete entire rows if column d equals 2925-6 & abc

    Yes, I did change that to a 2, but it still didn't delete the rows. It is strange. I wondered if maybe it was the beginning of the marco since I have about 10 steps that it does. I just looked at my macro and it has a 2 in both lines. I changed the second line only to a 2 and it still didn't work. It always deletes the first header line. I am puzzled. Do you have any other suggestions?

  4. #4
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Macro to delete entire rows if column d equals 2925-6 & abc

    Hello Triscia,

    Further to what TMS said above, try this subtle change to the code:-

    Please Login or Register  to view this content.
    Cheerio,
    vcoolio

  5. #5
    Forum Contributor
    Join Date
    10-03-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: Macro to delete entire rows if column d equals 2925-6 & abc

    That worked, but is there any way to tell it not to delete the first row, which is the header row? Thanks!

  6. #6
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Macro to delete entire rows if column d equals 2925-6 & abc

    Hello Triscia,

    If you take the code out into its own work book to test it (as per the attached), you'll see that it works and the Headings stay put. This would suggest that there is something going on elsewhere in the rest of your code which is affecting this part of it.

    Change some of the fictitious data in Column D in the test work book to your numeric value to see how it works.

    Cheerio,
    vcoolio.
    Attached Files Attached Files
    Last edited by vcoolio; 05-14-2015 at 07:52 AM.

+ 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. Create a macro to delete rows if column d =2529-3 for an entire sheet
    By Triscia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2015, 03:21 PM
  2. Delete Rows where column P equals column AA
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-24-2012, 05:18 AM
  3. [SOLVED] Macro to Copy Entire Rows if Column Equals
    By Andrew.Trevayne in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-21-2012, 09:46 PM
  4. Replies: 3
    Last Post: 04-19-2012, 10:45 AM
  5. Delete rows in all worksheets where column A equals string
    By excelforum123 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-13-2010, 09:25 AM

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