excel - 下拉自定义隐藏和取消隐藏
问题描述
- 我已经有下拉菜单,其中显示了不同的部门名称,例如:PM、SCM,包括NONE等。
我的期望:
我希望代码以这样一种方式运行,即当我选择 PM 时,它应该只显示 PM。当我选择 PM 和 SCM 时,它们都应该被看到,而其他部门应该被隐藏。
当我为该单元格选择NONE时,该特定部门应该被隐藏,而其他部门(如果有的话)应该仍然可见。
解决方案
我的查询代码
Sub Hide2ndFix()
'
' Hide2ndFix Macro
'
Dim RowCnt As Long, uRng As Range
Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim s As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
BeginRow = 2
EndRow = 20
ChkCol = 1
Set s = Range("A2:A20")
With s
.EntireRow.Hidden = True
End With
str1 = Range("C3").Value
str2 = Range("C4").Value
str3 = Range("C5").Value
For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value = str1 Or Cells(RowCnt, ChkCol).Value = str2 Or Cells(RowCnt, ChkCol).Value = str3 Then
If uRng Is Nothing Then
Set uRng = Cells(RowCnt, ChkCol)
Else
Set uRng = Union(uRng, Cells(RowCnt, ChkCol))
End If
End If
Next RowCnt
If Not uRng Is Nothing Then uRng.EntireRow.Hidden = False
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
推荐阅读
- python - Asciimatics 键盘输入
- c# - 不完整的堆栈跟踪信息
- android - Android parse-SDK-android 和 facebook SDK 不兼容
- django - Django 中的 OneToOneField
- node.js - 请告诉我如何在流管道在 nodeJS 中完全工作后打印文件中的空间
- node.js - 如何在 Heroku 上运行两台服务器?
- azure - Azure AD B2C 中的登录电子邮件域验证
- c# - C# 等效于 python3 int.to_bytes
- node.js - 我们如何将超过 200 万条记录的大量数据从 mongo 表达发送到节点 js
- hyperledger-fabric - 错误:调用期间背书失败。响应:状态:500 消息:“模拟错误: