+ Reply to Thread
Results 1 to 3 of 3

Macro to delete rows based on contents of specific column

  1. #1
    Registered User
    Join Date
    12-31-2015
    Location
    Howell, Michigan
    MS-Off Ver
    2012
    Posts
    2

    Question Macro to delete rows based on contents of specific column

    Hey guys,

    I looked at some other questions similar to this one, but I have two things I'm trying to accomplish so I just went ahead and posted a thread. In the attached screenshot, I am trying to do two things:


    1) Column E was a calculated by running a vlookup of column C on another sheet. The values in column E will be either #N/A or the value of its corresponding cell in column C. I should note that they have been copied and pasted so that the actual values are in the column and not the fromula used to obtain them. What I am trying to do is basically delete any row where the value is not #N/A (IOW anywhere where columns C and E have the same value). I just recently copied and pasted the values as mentioned above as I thought maybe it was having issues because the formula was in there (not sure if that step is needed or not though).

    2) Column Z has values of 0, 1, 2, 3, 4, 7, H, C, or it is blank. Those are the only values it will have. With that column, I am trying to delete any row where the value is 2, 3, 4, 7, H, or C. I have tried the following code, and it runs but for some reason doesn't touch row 2 (also takes a long time to run)

    \CODE
    Sub Removing_Xpress()
    '
    ' Removing_Xpress Macro

    Dim i As Long, j As Long, rw As Long
    Dim rng As Range, cel As Range
    Dim arrWords
    Dim xlCalc As XlCalculation
    arrWords = Array(2, 3, 4, 7, "H", "C")
    xlCalc = Application.Calculation
    Set rng = Range("Z2:Z40000")
    For rw = rng.Rows(rng.Rows.Count).Row To rng.Rows(1).Row Step -1
    For j = 0 To UBound(arrWords)
    If InStr(1, rng(rw, 1), arrWords(j), vbTextCompare) Then
    bDel = True
    rng.Parent.Rows(rw).EntireRow.Delete
    Exit For
    End If
    Next
    Next
    Application.Calculation = xlCalc
    End Sub
    \CODE

    There might very well be a better way to accomplish this, but I haven't done a lot of VBA work in a long time and this code came after lots of online research.

    Any help you could provide would be appreciated. I'm sure this is a rather simple solution and I am overthinking it. Thanks everyone
    Attached Images Attached Images

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Macro to delete rows based on contents of specific column

    You can edit your post and add code tags.

    AA CodeTags.jpg

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to delete rows based on contents of specific column

    submit the workbook.
    If you are happy with my response please click the * in the lower left of my post.

+ 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. [SOLVED] delete rows based on column contents (new)
    By wingfield65 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-16-2014, 09:00 PM
  2. [SOLVED] delete rows based on column contents
    By wingfield65 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-04-2014, 03:17 PM
  3. [SOLVED] Macro to Delete Rows based on Specific Conditions
    By stockgoblin42 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-28-2013, 05:29 PM
  4. Macro to find word in column then delete contents in specified rows
    By Dleopoldi914 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2013, 10:26 AM
  5. Macro to delete several rows based on a cell's contents
    By ppp112 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2013, 01:16 PM
  6. Delete rows or Clear contents below a specific word is found in Column A
    By kishoremcp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-17-2012, 04:08 PM
  7. How can I delete rows based on specific criteria using a macro?
    By akouleze in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2011, 02:49 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