首页 > 解决方案 > 跨多个工作表求和时忽略隐藏工作表

问题描述

有人可以帮我解决这个问题吗?我有这个功能可以对多张纸上的单元格求和。但是,我也有一些我不想总结的隐藏表格。如何禁用我的函数从隐藏工作表中的单元格中读取值?我的代码:

Function AutoSum(rng As Range) As Variant
    AutoSum = 0
    Application.Volatile True
    For Each ws In Worksheets
        If Not ws Is Application.ThisCell.Parent Then
            AutoSum = AutoSum + ws.Range(rng.Address)
        End If
    Next
End Function

标签: excelvba

解决方案


尝试这个。我已经添加了这部分And ws.Visible = True

Function AutoSum(rng As Range) As Variant
    AutoSum = 0
    Application.Volatile True
    For Each ws In Worksheets
        If Not ws Is Application.ThisCell.Parent And ws.Visible = True Then
            AutoSum = AutoSum + ws.Range(rng.Address)
        End If
    Next ws
End Function

推荐阅读