+ Reply to Thread
Results 1 to 5 of 5

Thread: delete anything in colum "A" with more than 4 letters

  1. #1
    Registered User
    Join Date
    05-02-2011
    Location
    Northampton
    MS-Off Ver
    Excel 2010
    Posts
    8

    delete anything in colum "A" with more than 4 letters

    As the title suggests, I need a macro that will automatically look at colum A (except range A1) and then delete anything that is not alphabet letters i.e. a * or other charecters. Also need to delete if more than 4 letters long.

    Can you help?

    Thanks in advance
    Last edited by ollierice; 06-08-2011 at 05:31 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    re: delete anything in colum "A" with more than 4 letters

    try this for delate string longer then 4 characters
    
    sub check_delete()
    dim r as integer
    r = 2'starting row
    
    do until cells(r,1).value = ""
     if len(cells(r,1).value) > 4 then cells(r,1).value = ""
    r = r +1
    loop
    
    end sub
    Last edited by maczaq; 06-07-2011 at 07:08 AM.

  3. #3
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,154

    Re: delete anything in colum "A" with more than 4 letters

    ollierice

    Do you mean just keep cells with one to four letters only?

    Sub check_delete()
    Dim r As Integer
    r = 2 'starting row
    Do Until Cells(r, 1).Value = ""
     If Match_Keep(Cells(r, 1)) Then Cells(r, 1).Value = ""
    r = r + 1
    Loop
    
    End Sub
    Function Match_Keep(Rng As Range) As Boolean
        Dim RegEx As Object
        Dim Match_Stuff
        Match_Stuff = Rng.Text
        Set RegEx = CreateObject("vbscript.regexp")
            With RegEx
                .Global = True
                 .Pattern = "^([a-zA-Z]{1,4})$"
              If RegEx.Test(Match_Stuff) Then
            Match_Keep = False
            Else
            Match_Keep = True
            End If
            End With
          Set RegEx = Nothing
    End Function
    or remove numbers and symbols?
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  4. #4
    Registered User
    Join Date
    05-02-2011
    Location
    Northampton
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: delete anything in colum "A" with more than 4 letters

    Thanks very much.

  5. #5
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,154

    Re: delete anything in colum "A" with more than 4 letters

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

+ 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.2.0