+ Reply to Thread
Results 1 to 3 of 3

How to delete a row with specific values in a that fall between certain numbers

Hybrid View

John Swift How to delete a row with... 12-05-2014, 05:00 AM
JRidge Re: How to delete a row with... 12-05-2014, 07:25 AM
mehmetcik Re: How to delete a row with... 12-05-2014, 08:27 AM
  1. #1
    Registered User
    Join Date
    10-18-2014
    Location
    Ontario, Canada
    MS-Off Ver
    2013
    Posts
    30

    How to delete a row with specific values in a that fall between certain numbers

    Hello and thank you for you help.

    Basically I would like a macro that works through column A and deletes the row if a value is between 90000000 and 99999999.

    an example of the data I am using

    aa123456
    ab123456
    ac456879
    zz123456
    90000000
    95134756

    I would like the macro to delete the 90000000 and 95134756
    so the data would be like

    aa123456
    ab123456
    ac456879
    zz123456

    There can be up to 10,000 rows of data if this make a difference

    Thank you in advance for you help

  2. #2
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    265

    Re: How to delete a row with specific values in a that fall between certain numbers

    Found easily on the net and edited to meet your needs:

    Sub Delete_Rows()
    
     Dim rng As Range, cell As Range, del As Range
     Set rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
     For Each cell In rng
       
       If (cell.Value) >= 90000000 And (cell.Value) <= 99999999 Then
           If del Is Nothing Then
              Set del = cell
           Else: Set del = Union(del, cell)
           End If
        End If
     Next cell
     On Error Resume Next
     del.EntireRow.Delete
    End Sub
    If the solutions provided within this Thread takes care of your question:

    Please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.

    You can also click on * (star) Add Reputation to add reputation to those who have put their time and efforts to help you in this Thread.

    This is another way to say Thank You to them.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to delete a row with specific values in a that fall between certain numbers

    This is not as neat as JRidges Code but it should be faster:

    Sub Macro1()
    
    
    Dim del As Range
    
    LR = 1
    MYLoop: Range(Cells(LR, 1), Cells(Rows.Count, 1).End(xlUp)).Select
    If (ActiveCell.Value) >= 90000000 And (ActiveCell.Value) <= 99999999 Then GoTo CountLoop
    Selection.Find(9, LookIn:=xlValues, Lookat:=xlPart).Activate
    CountLoop:   If (ActiveCell.Value) >= 90000000 And (ActiveCell.Value) <= 99999999 Then
           If del Is Nothing Then
              Set del = ActiveCell
           Else: Set del = Union(del, ActiveCell)
           End If
        End If
    LR = ActiveCell.Row + 1
    If Cells(LR, 1).Value <> "" Then GoTo MYLoop
    On Error Resume Next
     del.EntireRow.Delete
     On Error GoTo 0
    End Sub

+ 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. Need Macro that Highlights Values which Fall In Specific Range
    By Esuric in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2014, 03:27 AM
  2. Delete cells that don't contain specific numbers
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2014, 11:15 AM
  3. I want to delete rows that include some specific serial numbers
    By danieldaniel1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2014, 12:07 PM
  4. [SOLVED] How to delete specific numbers and or sign in a column
    By mrsewer in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 07-25-2013, 03:54 PM
  5. vba - delete rows if they do not fall within dates
    By Zygoid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-08-2007, 02:48 AM

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