+ Reply to Thread
Results 1 to 4 of 4

Delete Row If Contains Any Letter A-Z.

Hybrid View

  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Delete Row If Contains Any Letter A-Z.

    Hello,
    Im having a terrible time trying to find anything on something like this and i would appreciate any help i could get.
    I have a list in column a of sheet1 like this

    11-06515
    mitchell
    62-06055
    62-06079
    KR3W.ai
    LRG.psd

    i would like to run a macro to search column A and if it contains a letter it would delete the entire ROW so the end result would end up like this.

    11-06515
    62-06055
    62-06079

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Delete Row If Contains Any Letter A-Z.

    try it
    Sub ert()
    Dim r As Range, rDel As Range
    Set rDel = Range("B1")
    For Each r In Range("A1", Cells(Rows.Count, 1).End(xlUp))
        If r.Value Like "*[a-zA-Z]*" Then Set rDel = Union(rDel, r)
    Next
    If Not rDel Is Nothing Then Intersect(Range("A:A"), rDel).EntireRow.Delete
    End Sub

  3. #3
    Registered User
    Join Date
    08-20-2012
    Location
    NJ, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Delete Row If Contains Any Letter A-Z.

    WOW! I cant believe it, you are amazing my friend.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Delete Row If Contains Any Letter A-Z.

    Try this,

    Option Explicit
    
    Sub ParseData()
        Dim rCell            As Range
        Dim cel
        Dim x                As Range
        
    
        Application.ScreenUpdating = False
        
        With CreateObject("vbscript.regexp")
            .Global = True
               For Each rCell In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
                .Pattern = "[a-zA-Z]"
                Set cel = .Execute(rCell)
                 Debug.Print cel.Count
                 If cel.Count <> 0 Then
                    If x Is Nothing Then
                      Set x = rCell
                    Else
                      Set x = Union(x, rCell)
                    End If
                 End If
            Next rCell
        End With
          x.EntireRow.Delete
        Application.ScreenUpdating = True
    End Sub
    Edit: Never mind nilem has sorted you out.
    Attached Files Attached Files
    Last edited by JapanDave; 08-21-2012 at 12:37 AM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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