Excel宏可以跨多个工作表隐藏行

时间:2013-09-13 15:35:25

标签: excel-vba excel-2007 vba excel

我有一个基于单元格值隐藏行的宏。我试图在工作簿中的多个工作表中使用它,但不是全部。我的代码似乎在同一张表中多次运行宏。

Sub HideRowsWbk()
Dim LastRow As Long
Dim Rng As Range
Dim ws As Worksheet

Application.ScreenUpdating = False
With ThisWorkbook
    For Each ws In .Worksheets
        Select Case ws.Name
        Case "0000_Index", "000_BidItems", "000_EntrySheet", "000_PayReqs"
             'do nothing - exclude these sheets

        Case Else
            With ws
                LastRow = Range("A65536").End(xlUp).Row '
                Set Rng = Range("M15:M" & LastRow) 'choose column where value exists

                For Each cell In Rng
                    If cell.Value = "0" Or cell.Value = "-" Then  'checks if cell value is 0 or -
                        cell.EntireRow.Hidden = True
                    End If
                Next cell
            End With
        End Select
    Next ws
End With

Application.ScreenUpdating = True

End Sub

请告诉我我做错了什么以及如何解决这个问题。另请告诉我如何提高我的最低编码技能。我正在使用Excel 2007。

谢谢。

1 个答案:

答案 0 :(得分:1)

使用:

LastRow = .Range("A65536").End(xlUp).Row '
Set Rng = .Range("M15:M" & LastRow) 'choose column where value exists

”可以使用 ws