Skip one worksheet and process the remaining worksheets

前端 未结 2 1042
迷失自我
迷失自我 2020-12-22 01:16

I was working with a vba code which remove all the rows which dont have word \"Statement No\" in it from all available worksheets. But anyhow i want it to skip the first wor

相关标签:
2条回答
  • 2020-12-22 01:27

    Just tell it to ignore the sheet by checking each sheet name:

    Sub doit()
    
        Application.DisplayAlerts = False
    
        Dim r As Long, lr As Long
        Dim sh As Worksheet
    
        For Each sh In Sheets
            If sh.Name <> "IgnoreThisSheet" Then
                lr = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row
                For r = lr To 1 Step -1
                    If InStr(sh.Cells(r, 1), "Statement No") = 0 Then sh.Rows(r).Delete
                Next r
            End If
        Next
    
        Application.DisplayAlerts = True
    
    End Sub
    

    Edit: You may also want to change Sheets to WorkSheets in your For Each loop. A worksheet contains rows, columns, etc. A sheet can be a chart sheet, macro sheet or dialog sheet. http://blogs.msdn.com/b/frice/archive/2007/12/05/excel-s-worksheets-and-sheets-collection-what-s-the-difference.aspx

    0 讨论(0)
  • 2020-12-22 01:43

    If the sheet name is always going to be the same then you could use this ..

    If sh.Name <> "Sheet 1" Then ' Or whatever the sheet is called
       .. more code
    End If
    
    0 讨论(0)
提交回复
热议问题