周一至周五 : 08:30 - 17:30 客服专员电话/微信:17301649371 QQ:2627049059
微信咨询

扫码微信咨询

关注公众号

关注微信公众号

电话: 021 5161 9370
返回顶部
VBA快速隐藏周围区域
显示全部楼层 倒序浏览 发表日期 2014-01-23 12:20:34 1926次阅读 0次回复
Sub HiddenSurroundRange()
Dim CelFirst As Range, CelLast As Range
    If Not Selection Is Nothing Then
        With Selection
            '当前选中区域的第一个单元格
            Set CelFirst = .Cells(1)
            '当前选中区域的最后一个单元格
            Set CelLast = .Cells(.Cells.Count)
        End With
        If CelFirst.Address <> "$A$1" Then
            '蓝色区域
            With Range([a1], CelFirst.Offset(IIf(CelFirst.Row = 1, 0, -1), IIf(CelFirst.Column = 1, 0, -1)))
                '如果当前选中区域不包括第一行,则隐藏蓝色区域所在的行
                If CelFirst.Row <> 1 Then .EntireRow.Hidden = True
                '如果当前选中区域不包括第一列,则隐藏蓝色区域所在的列
                If CelFirst.Column <> 1 Then .EntireColumn.Hidden = True
            End With
        End If
        If CelLast.Address <> "$IV$65536" Then
            '与上面类似处理绿色区域
            With Range(CelLast.Offset(IIf(CelLast.Row = 65536, 0, 1), IIf(CelLast.Column = 256, 0, 1)), [IV65536])
                If CelLast.Row <> 65536 Then .EntireRow.Hidden = True
                If CelLast.Column <> 256 Then .EntireColumn.Hidden = True
            End With
        End If
    End If
End Sub

联系QQ:1327452797
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则  允许回帖邮件提醒楼主

快表软件是国内较早研究表格类软件开发平台的团队之一,迄今已有十多年的行业经验.致力于为企事业单位提供实用可靠的数字化平台。
  • 微信公众号

  • 微信小商店

  • 微信客服

  • Powered by Discuz! X3.4 | Copyright © 2022-2024, XiRong Soft. | 快表软件
  • 沪ICP备13033196号 | 营业执照 |上海西戎软件科技有限公司|沪公网安备31011502002146号|沪ICP备13033196号 |