ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 352|回复: 2

[求助] 根据设定条件隐藏列。。可以出结果。。就是有个问题,丑

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-3-15 10:33 | 显示全部楼层 |阅读模式
Capture.JPG

为啥这么丑~

代码如下~大神帮我看看啥问题~
test2 - hide.rar (22.27 KB, 下载次数: 3)

  1. Sub Button2_Click()
  2.   On Error Resume Next
  3.     Application.ScreenUpdating = False
  4.     Application.DisplayAlerts = False
  5.     Dim nRow As Integer, nCol As Integer, nFillCol As Integer
  6.    

  7.    
  8.     i = Cells(4, Columns.Count).End(1).Column '
  9.     y = Cells(Rows.Count, 1).End(3).Row

  10.     With Sheet1
  11.         
  12.         For nCol = 2 To i
  13.             If .Cells(6, nCol) = "Sum of FF2" And .Cells(6, nCol + 1) = "Sum of FF1" Then

  14.                 For nRow = 7 To y

  15.                     If InStr(Range(Cells(7, nCol), Cells(y, nCol)).NumberFormatLocal, "$") Then
  16.                     Range(Columns(nCol), Columns(nCol + 1)).Select
  17.                     Selection.Columns.Group
  18.                      End If



  19.                    Next
  20.                   
  21.             End If

  22.         Next
  23.     End With
  24.    

  25.    ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
  26.     Application.DisplayAlerts = True
  27.     Application.ScreenUpdating = True
  28. End Sub

复制代码




TA的精华主题

TA的得分主题

发表于 2019-3-15 11:15 | 显示全部楼层
在第21行后面加一句:Exit For

评分

1

查看全部评分

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-3-15 15:08 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
简化了一下代码,又有新问题 test2 - hide.rar (22.64 KB, 下载次数: 1)

条件是 如果是FF2 或者FF1(因为是举例,实际代码不能用ff*简化) 然后下面的值含$
就折叠但是运行后FF1未折叠。

  1. If .Cells(6, nCol) = "Sum of FF2" Or .Cells(6, nCol + 1) = "Sum of FF1" And InStr(Range(Cells(7, nCol), Cells(y, nCol)).NumberFormatLocal, "$") Then
复制代码






Capture.JPG


完整代码如下。。。
  1. Sub Button2_Click()
  2.   On Error Resume Next
  3.     Application.ScreenUpdating = False
  4.     Application.DisplayAlerts = False
  5.     Dim nRow As Integer, nCol As Integer, nFillCol As Integer
  6.         
  7.     i = Cells(4, Columns.Count).End(1).Column
  8.     y = Cells(Rows.Count, 1).End(3).Row

  9.     With Sheet1
  10.         
  11.         For nCol = 2 To i
  12.             If .Cells(6, nCol) = "Sum of FF2" Or .Cells(6, nCol + 1) = "Sum of FF1" And InStr(Range(Cells(7, nCol), Cells(y, nCol)).NumberFormatLocal, "$") Then

  13.                 For nRow = 7 To y

  14.                     Range(Columns(nCol), Columns(nCol)).Select
  15.                     Selection.Columns.Group
  16.                 Exit For
  17.             
  18.             Next
  19.         End If
  20.         Next
  21.     End With
  22.    ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
  23.     Application.DisplayAlerts = True
  24.     Application.ScreenUpdating = True
  25. End Sub
复制代码




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

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-26 03:03 , Processed in 0.035278 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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