Excel 一键隐藏多个相同格式sheet页的某些列

1、按 Alt+F11 进入开发人员选项

在这里插入图片描述

2、插入 > 模块

在模块中插入以下代码后,点击运行

在这里插入图片描述

' define meth_to_hide_Column() method header
Sub meth_to_hide_Column()
   ' declaring required variables
   Dim i As Integer
   Dim col_s As String
   On Error Resume Next
   ' define input box
   col_s = Application.InputBox("Enter column range to hide,Eg A:A OR A:B", _
      "VBA code block result", , , , , , 2)
   ' if column
   If col_s = "" Then
      ' display message
      MsgBox "Empty columns", vbInformation, "Enter valid data columns!!!"
      'end of sub block
      Exit Sub
   ' end of if block
   End If
   ' for each loop expression
   For i = 1 To ThisWorkbook.Worksheets.Count
      ' setting column value to hidden
      ThisWorkbook.Sheets(i).Columns(col_s).Hidden = True
   ' next statement
   Next i
   ' use go to loop
   On Error GoTo 0
' end of sub block
End Sub

3、输入要隐藏的列

例如:

1)想要隐藏多列,如a到c列,输入a:c
2)想要隐藏单列,如f列,输入f

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值