找回密码
 立即注册
搜索

修改程序,根据部分字段,来隐藏固定列,可能含有特殊字符

1
回复
968
查看
[复制链接]

3

主题

7

帖子

8

幻币

一流武者

Rank: 3Rank: 3

积分
224
QQ
2019-3-16 06:28:34 显示全部楼层 |阅读模式
对固定含有某字符的列,进行隐藏,谢了一个简单的程序,但是运用到工作中生成的文件无效,模拟的文件,可以用,请教下,如何修改,程序,谢谢。
hide column.zip (17.34 KB, 下载次数: 13)
PPT学习论坛
回复

使用道具 举报

0

主题

9

帖子

75

幻币

一流武者

Rank: 3Rank: 3

积分
345
QQ
2019-3-16 08:42:39 显示全部楼层
含有字段的 rev_raised,进行隐藏
    Sub hide()
    Dim rows, cols As Integer
    'batch all sheets in this workbook
    For Each sh In ThisWorkbook.Sheets

        If sh.Name <> &quot;content&quot; And sh.Name <> &quot;summary&quot; Then   'read all sheets except the two sheets
        With sh
            .Unprotect
            rows = .[A65536].End(xlUp).Row 'get row number

            cols = .[IV1].End(xlToLeft).Column 'get column number

            'hide

             Key = Array(&quot;rev_raisedDate_&quot;, &quot;rev_raisedDay_&quot;)

             For j = 1 To cols


                 Set rngexp = CreateObject(&quot;VBScript.RegExp&quot;)

                 With rngexp
                   .Global = True
                   .Pattern = &quot;^[wd_-+.]+$&quot;
                 End With

                '.Cells(4, j) = rngexp.Replace(.Cells(4, j).Value, &quot;&quot;)



                '.Cells(4, j).Value = Application.Clean(.Cells(4, j).Value)

                 For k = 0 To 1
                   Set Rng = .Cells(4, j).Find(what:=Key(k), lookat:=xlWhole)
                   If Not Rng Is Nothing Then .Columns(j).Hidden = True
                 Next k

               'If Trim(.Cells(1, j).Value) = &quot;a1&quot; Then .Columns(j).Hidden = True

               'If InStr(Trim(.Cells(1, j)), &quot;_date&quot;) > 0 Then .Columns(j).Hidden = True

               'If Right(Trim(.Cells(1, j)), 4) = &quot;date3&quot; Then .Columns(j).Hidden = True

               'If Find(&quot;_vsdate_dddd&quot;, .Cells(1, j), 1) > 0 Then .Columns(j).Hidden = True


             Next j

             'show all columns
             'For j = 1 To cols

             '  .Columns(j).Hidden = False

            ' Next j

        End With
        End If
    Next sh

    End Sub

复制代码


&quot;Date&quot;&  vbcrlf &&quot;[rev_raisedDate_]&quot;

&quot;Days&quot; &  vbcrlf & &quot;[rev_raisedDay_]&quot; 104148c6hiwfpuaef0uhcq.png
PPT学习论坛
回复 支持 反对

使用道具 举报

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