Delete Column in worksheets containing text

  • I have a workbook with about 30 worksheets. I want to delete column 4 only in worksheets that contain the text"NIFTY".

    Code
     Sub FindERROR() Dim SearchString As String 
    Dim SearchRange As Range, cl As Range 
    Dim FirstFound As String 
    Dim sh As Worksheet ' Set Search value SearchString = "NIFTY"
     Application.FindFormat.Clear loop through all sheets 
    For Each sh In ActiveWorkbook.Worksheets
     Columns(4).Delete 
    End Sub 

    I couldn't get the VBA code to run. Any help with the code would be appreciated :)

    Edited once, last by Carim: Adjusted Font SIze .... Very Large Font Size can be interpreted as Shouting ... ().

  • Hi,


    You do mention "Delete Row" in your thread title ... and "Delete Column 4" in your message ...


    Thanks for clarifying ...


    In addition, with 30 worksheets, do you have headings in Row 1 which would help using the Filter feature ....

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hello Carim,


    Oops! My bad. Its columns that I want to delete. I wonder if its possible to edit the thread title.


    One colummn ie col D has the text NIFTY in one or two worksheets, so worksheets that have the delinquent text, is where i want to del the entire column.

    The worksheets dont have a header.


    Thankyou for reaching out

  • Carim

    Changed the title of the thread from “Delete Row in worksheets containing text” to “Delete Column in worksheets containing text”.
  • Hi,


    So basically, a macro could run and search for your text NIFTY in Column D, and delete the entire column, in case this text is found ...


    Is that right ?

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

    Edited 2 times, last by Carim ().

  • Hi,


    Please make a copy of your original file and ONLY test the Delete Macro with your test copy file ;)


    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Thanks Carim,


    A small issue. Its probably searching for the txt (NIFTY) in Col D.


    The txt could be in any col, if found then del col 4 of that worksheet


    Hope its not too much of trouble

  • OK ...


    Hope this will work out as expected ;)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • OOPS ... Sorry for my mistake =O



    Fingers crossed .... ;)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Glad to hear you found a 'working' solution :thumbup:


    Thanks a lot for your Thanks AND for the Like  :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!