Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 对于隐藏行,工作表的运行速度非常慢_Excel_Vba_Excel 2013 - Fatal编程技术网

Excel 对于隐藏行,工作表的运行速度非常慢

Excel 对于隐藏行,工作表的运行速度非常慢,excel,vba,excel-2013,Excel,Vba,Excel 2013,由于某些原因,每当宏运行时,此shee的行为都非常缓慢。这正成为一个问题,因为每次我尝试更改不属于该范围的未隐藏单元格的信息时,它仍会运行更新,并且需要将近5-10秒才能完成 要解决这个问题,需要对公式进行哪些更改 Private Sub Worksheet_Change(ByVal Target As Range) Dim c As Range For Each c In Range("A7:A98") If c.Value = 0 And c.Value

由于某些原因,每当宏运行时,此shee的行为都非常缓慢。这正成为一个问题,因为每次我尝试更改不属于该范围的未隐藏单元格的信息时,它仍会运行更新,并且需要将近5-10秒才能完成

要解决这个问题,需要对公式进行哪些更改

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim c As Range


    For Each c In Range("A7:A98")
        If c.Value = 0 And c.Value = vbNullString Then
        c.EntireRow.Hidden = True
        End If
    Next c

    For Each c In Range("A7:A98")
        If c.Value <> 0 And c.Value <> vbNullString Then
        c.EntireRow.Hidden = False
        End If
    Next c

End Sub
Private子工作表\u更改(ByVal目标作为范围)
调光范围
对于范围内的每个c(“A7:A98”)
如果c.Value=0且c.Value=vbNullString,则
c、 EntireRow.Hidden=True
如果结束
下一个c
对于范围内的每个c(“A7:A98”)
如果c.值为0,c.值为vbNullString,则
c、 EntireRow.Hidden=False
如果结束
下一个c
端接头

像这样的东西应该适合你:

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rCheck As Range
    Dim rCell As Range
    Dim rHide As Range
    Dim lCalc As XlCalculation

    Set rCheck = Me.Range("A7:A98")

    With Application
        lCalc = .Calculation
        .Calculation = xlCalculationManual
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    On Error GoTo CleanExit

    If Not Intersect(Target, rCheck) Is Nothing Then
        rCheck.EntireRow.Hidden = False
        For Each rCell In rCheck
            If rCell.Value = 0 And rCell.Value = vbNullString Then
                If rHide Is Nothing Then
                    Set rHide = rCell
                Else
                    Set rHide = Union(rHide, rCell)
                End If
            End If
        Next rCell
    End If

    If Not rHide Is Nothing Then rHide.EntireRow.Hidden = True

CleanExit:
    With Application
        .Calculation = lCalc
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub

您的逻辑看起来很粗略,很难说您想做什么,但是您的逻辑可以缩短,并用于确定布尔值.Hidden

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("A7:A98")) Is Nothing Then
        On Error GoTo safe_exit
        Application.EnableEvents = False
        Dim trgt As Range
        For Each trgt In Intersect(Target, Range("A7:A98"))
            trgt.EntireRow.Hidden = CBool(trgt.Value = vbNullString)
        Next trgt
    End If

safe_exit:
    Application.EnableEvents = True

End Sub

最糟糕的是,你的代码甚至没有运行!目标范围导致类型不匹配!但我接受优化是一个有效的问题<代码>如果目标范围(“A7:A98”)那么我忘了我在那里有。如果目标范围(“A7:A98”),那么我是不是在破坏代码,试图找出如何忽略被检查单元格以外的单元格。。。很明显,它不起作用。我会相应地编辑这篇文章。