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