+ Reply to Thread
Results 1 to 7 of 7

delete row based on criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    delete row based on criteria

    hello,
    I have some datas :
    DRB1obed
    GRC2vecera
    ranajky
    olovrant

    and I need this : If first 3 characters are capital letter followed by number then do nothing, but if not then delete whole row ... it means after macro (or function?) result should be :
    DRB1obed
    GRC2vecera

    thanks for any help !
    Last edited by miso.dca; 01-02-2010 at 04:45 PM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: delete row based on criteria

    You could use VBA for sure but on the off chance it's a one off you could equally just insert a helper calc, eg:

    B1: 
    =IF(EXACT(UPPER(LEFT(A1;3));LEFT(A1;3))*(MIN(FIND({1\2\3\4\5\6\7\8\9\0};A1&1234567890))=4);1;NA())
    copied down
    once the above is in place:

    -- Highlight column B -> F5 -> Special -> Formulas: uncheck all but Errors -> OK
    -- via Home Tab on Ribbon -> Delete Sheet Rows
    -- finally delete column B to remove legacy formulae.
    Last edited by DonkeyOte; 01-02-2010 at 04:16 PM. Reason: changed to Slovak based locale delimiter

  3. #3
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: delete row based on criteria

    thanks ! I've tried it but ... there is some mistake>
    =FIND({1\2\3\4\5\6\7\8\9\0};A1&1234567890)
    or my excel is bad?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: delete row based on criteria

    In my locale it would be:

    B1: 
    =IF(EXACT(UPPER(LEFT(A1,3)),LEFT(A1,3))*(MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&1234567890))=4),1,NA())
    copied down
    see the attached - it should auto translate to your own settings upon opening - from which you can copy the formula (to your file).
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: delete row based on criteria

    GREAT ! thank you

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,922

    Re: delete row based on criteria

    The code below worked for the small sample data provided.
    Option Explicit
    Sub TEST()
        Dim CharPos     As Long, _
            RowCount    As Long, _
            TestRow     As Long
        
        RowCount = Cells(Rows.Count, "A").End(xlUp).Row
        
        For TestRow = RowCount To 1 Step -1
            
            CharPos = 0
            Do
                CharPos = CharPos + 1
            Loop While (CharPos < Len(Range("A" & TestRow).Value) And (Asc(Mid(Range("A" & TestRow).Value, CharPos, 1)) - 91 > 0))
            If CharPos = Len(Range("A" & TestRow).Value) Then
                'Debug.Print Range("A" & TestRow).Value
                Range("A" & TestRow).EntireRow.Delete
            End If
        Next TestRow
    End Sub
    Ben Van Johnson

  7. #7
    Forum Contributor
    Join Date
    07-26-2009
    Location
    Slovakia
    MS-Off Ver
    Excel 2019
    Posts
    244

    Re: delete row based on criteria

    thanks buddy ! it works perfectly, only when cell contains two or more words it doesnt work it is possible to solve it somehow?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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