Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2533|回复: 4

[已解决]VBA把列隐藏 但合计数

[复制链接]
发表于 2017-3-31 23:15 | 显示全部楼层 |阅读模式
本帖最后由 laoau138 于 2017-4-6 16:25 编辑

VBA把列隐藏  但合计数


最佳答案
2017-4-6 13:05
  1. Sub aaa()
  2. Dim j&, clm&, rw&, rng As Range, rng1 As Range
  3. clm = [iv1].End(1).Column
  4. rw = [a65536].End(3).Row - 1
  5. For j = 2 To clm
  6.   Set rng1 = Range(Cells(2, j), Cells(rw, j))
  7.   If Application.CountA(rng1) = 0 Then
  8.     If rng Is Nothing Then Set rng = rng1 Else Set rng = Union(rng, rng1)
  9.   End If
  10. Next
  11. rng.EntireColumn.Hidden = True
  12. End Sub
复制代码

VBA把列隐藏 但合计数.rar

5.25 KB, 下载次数: 7

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2017-4-6 13:05 | 显示全部楼层    本楼为最佳答案   
  1. Sub aaa()
  2. Dim j&, clm&, rw&, rng As Range, rng1 As Range
  3. clm = [iv1].End(1).Column
  4. rw = [a65536].End(3).Row - 1
  5. For j = 2 To clm
  6.   Set rng1 = Range(Cells(2, j), Cells(rw, j))
  7.   If Application.CountA(rng1) = 0 Then
  8.     If rng Is Nothing Then Set rng = rng1 Else Set rng = Union(rng, rng1)
  9.   End If
  10. Next
  11. rng.EntireColumn.Hidden = True
  12. End Sub
复制代码
回复

使用道具 举报

发表于 2017-4-6 13:18 | 显示全部楼层
Public Sub abc()

    iColumn = [IV1].End(xlToLeft).Column

    For i = 2 To iColumn
        iRow = Cells(1, i).End(xlDown).Row
        If iRow = 33 Then Columns(i).EntireColumn.Hidden = True
    Next

End Sub
回复

使用道具 举报

发表于 2017-4-6 13:52 | 显示全部楼层
回复

使用道具 举报

发表于 2017-4-6 13:55 | 显示全部楼层
判断空行的话你的效率应该高一点吧,但是逐列隐藏肯定没有一次性隐藏来得快。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-19 15:33 , Processed in 0.318102 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表