Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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
Vba 优化隐藏列的速度_Vba_Excel - Fatal编程技术网

Vba 优化隐藏列的速度

Vba 优化隐藏列的速度,vba,excel,Vba,Excel,我编写了一个简短的脚本,用于根据单元格值在中隐藏列 该脚本可以工作,但速度非常慢,并且在列数较大的情况下经常出现Excel错误,例如>200列 Sub Bouton_hidingColumns() Dim NumColonne As Integer For NumColonne = Range("I11").Column To Range("IH11").Column Step 3 If WorksheetFunction.Sum(Range(Cells(11, NumColonne)

我编写了一个简短的脚本,用于根据单元格值在中隐藏列

该脚本可以工作,但速度非常慢,并且在列数较大的情况下经常出现Excel错误,例如>200列

Sub Bouton_hidingColumns()
Dim NumColonne As Integer

For NumColonne = Range("I11").Column To Range("IH11").Column Step 3
    If WorksheetFunction.Sum(Range(Cells(11, NumColonne), Cells(119, NumColonne))) = 0 Then
         Columns(NumColonne).Resize(, 3).Hidden = True
    End If
Next NumColonne

End Sub
列数较高时脚本失败的示例:

不可能在等级范围内完成固有的隐藏

(在英语中,无法设置range类的隐藏属性)


有人能提出解决办法吗?提前感谢您的帮助。

ActiveWindow.Visible=False
在脚本开头有时会产生很大的不同

一定要把
ActiveWindow.Visible=True
捕捉错误。

测试然后隐藏在单次射击中运行对我来说没问题

Sub OneWay()

Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range

Set rng1 = Range("I11:IH119")
For Each rng2 In rng1.Columns
    If rng2.Column Mod 3 = 0 Then
       If Application.Sum(rng2) = 0 Then
          If Not rng3 Is Nothing Then
              Set rng3 = Union(rng3, rng2.Resize(, 3))
          Else
               Set rng3 = rng2.Resize(, 3)
          End If
       End If
    End If
Next

If Not rng3 Is Nothing Then rng3.EntireColumn.Hidden = True

End Sub

当您得到那个错误时,列号是多少?我提供了一个关于执行缓慢的提示。