Delete Nth Row In All Worksheets If Cell Meets Criteria

  • I want to scan all sheets in a workbook and to delete a first row where a value in cell(1,1) is "table".


    It delete only in an active sheet. What's wrong?

  • Re: Delete First Row In Worksheets


    Try -


    Code
    Sub DeleteFirstRowInWorksheet() 
        Dim SheetName As Worksheet 
        Dim i As Integer 
         
        For Each SheetName In Sheets 
            If SheetName.Range("A1") = "table" Then 
                SheetName.Rows("1:1").Delete Shift:=xlUp 
            End If 
        Next SheetName 
    End Sub


    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

  • Re: Delete First Row In Worksheets


    Hi Jonny, number of worksheets is irrelevant.


    The string "table" must match exactly - it is case sensitive.


    To avoid, this convert the string to uppercase and then compare...



    Also, the code does not actually activate each sheet - there is no need to activate or select a sheet, as long as you reference the sheet name.


    Ger

    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

Participate now!

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