+ Reply to Thread
Results 1 to 6 of 6

if cell contains <> specific word, then delete others rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Hyderbad
    MS-Off Ver
    Excel 2003
    Posts
    123

    if cell contains <> specific word, then delete others rows

        Sub specificwordInsetence()
        Last = Cells(Rows.Count, "c").End(xlUp).Row
        For i = Last To 1 Step -1
            If (Cells(i, "c").Value) <> "*deferred*" And (Cells(i, "c").Value) <> "*future*" _
            And (Cells(i, "c").Value) <> "*tax*" Then
                Cells(i, "c").EntireRow.Delete
            End If
        
        Next i
        Cells(1, 4).Select
        Application.ScreenUpdating = True
    End Sub
    List of strings : Bold String should be remain and other strings should delete by 1 step -1

    Interests in Leasehold Land Held for Own Use under Operating Leases
    Intangible Assets
    Goodwill
    Interest in an Associate, Net
    Prepayment for Acquisition of an Intangible Asset
    Available-For-Sale Financial Asset
    Financial Asset At Fair Value through Profit or Loss
    Deferred Tax Assets
    Current Assets
    Current Assets
    Inventories
    Trade and Other Receivables
    Pledged Bank Deposits
    Cash and Cash Equivalents
    Current Liabilities
    Current tax Liabilities
    Contract Liabilities
    Trade and Other Payables
    Bank and Other Borrowings
    Financial Liabilities At Fair Value through Profit or Loss
    Current Taxation
    future income tax liabilities
    Current Assets
    Net Current Liabilities
    Non-Current Assets
    Total Assets
    Non-Current Liabilities
    Total Assets Less Current Liabilities
    Non-Current Liabilities
    Other Borrowings
    Financial Liabilities At Fair Value through Profit or Loss
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,936

    Re: if cell contains <> specific word, then delete others rows

    I will assume your code and your sample workbook do not exactly match as your code is looking in column C for "Tax" etc. but in your sample workbook those are in column B. However your approach still doesn't work if you make them both column B.

    Try this approach using InStr:
    Sub specificwordInsetence()
        Last = Cells(Rows.Count, "b").End(xlUp).Row
        For i = Last To 1 Step -1
            If InStr(1, Cells(i, "b"), "deferred", 1) = 0 And _
               InStr(1, Cells(i, "b"), "future", 1) = 0 And _
               InStr(1, Cells(i, "b"), "tax", 1) = 0 And _
               InStr(1, Cells(i, "b"), "DTLNC", 1) = 0 Then
                Cells(i, "c").EntireRow.Delete
            End If
        Next i
        Cells(1, 4).Select
        Application.ScreenUpdating = True
    End Sub
    Worth noting that also "Gross Deferred Tax Assets" would remain after the code has run, as would "Current Taxation".

    BSB

  3. #3
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Hyderbad
    MS-Off Ver
    Excel 2003
    Posts
    123

    Re: if cell contains <> specific word, then delete others rows

    Thanks "BadlySpelledBuoy" Worked Percetly...

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: if cell contains <> specific word, then delete others rows

    Here's my attempt that will also delete blank entries in Col. B (needs to be run from the sheet in question):

    Option Explicit
    Sub Macro1()
    
        Dim varMyText As Variant
        Dim lngLastRow As Long
        Dim lngMyRow As Long
            
        Application.ScreenUpdating = False
        
        varMyText = "Deferred Tax Assets,Current Tax Liabilities,Future Income Tax Liabilities"
            
        lngLastRow = Cells(Rows.Count, "B").End(xlUp).Row
        
        For lngMyRow = lngLastRow To 1 Step -1
            If Len(Range("B" & lngMyRow)) = 0 Or InStr(StrConv(varMyText, vbUpperCase), StrConv(Range("B" & lngMyRow), vbUpperCase)) = 0 Then
                Rows(lngMyRow).EntireRow.Delete
            End If
        Next lngMyRow
        
        Application.ScreenUpdating = True
    
    End Sub
    Note you should initially run this on a copy of your data as the results cannot be undone if they're not as expected.

    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: if cell contains <> specific word, then delete others rows

    Another option...
    Sub futuretax()
    With Range("E1:E" & Range("B" & Rows.Count).End(xlUp).Row)
        .Formula = "=IF(SUM(COUNTIF(B1,{""future income tax liabilities"",""Deferred Tax Assets"",""Current tax Liabilities""})),""x"","""")"
        .AutoFilter 1, " "
        .SpecialCells(12).EntireRow.Delete
        .AutoFilter
        .ClearContents
    End With
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,936

    Re: if cell contains <> specific word, then delete others rows

    Glad I could help.

    BSB

+ 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 all rows in which column does not contain specific word
    By BVT3030 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-22-2015, 12:57 AM
  2. Delete rows that do no contain a specific word
    By Tesseh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2014, 02:08 AM
  3. [SOLVED] delete rows when column has specific word(s)
    By chrisblackman in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-22-2013, 10:21 PM
  4. [SOLVED] Macro to delete rows that DO NOT contain specific word
    By enfieldsteve in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-19-2013, 10:59 AM
  5. [SOLVED] Need a macro to delete rows with specific word
    By renjithvakkayil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2013, 12:54 PM
  6. Delete all rows that dont contain a specific word.
    By BPSJACK in forum Excel General
    Replies: 4
    Last Post: 03-15-2012, 05:05 AM
  7. Macro to look for a specific word and delete rows
    By excelaspire0219 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-27-2009, 06:35 PM

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