如何在Excel 2013/2016中使用的VBA宏来根据下拉列表选项来隐藏或取消隐藏特定列
时间:2023-09-01 16:42:05
本文将讲述如何根据Excel中的下拉列表选择来自动隐藏特定的列。如何在Excel 2013/2016中使用的VBA宏来根据下拉列表选项来隐藏或取消隐藏特定列。
根据下拉列表选项来隐藏或取消隐藏列
假设您在单元格A2中有一个下拉列表,其中两个值为“TRUE”和“FALSE”。并且B列和C列都包含一些文本字符串值。如果你想在下拉列表中选择TRUE项时隐藏整个B列,或者你想在在Cell A2的下拉列表中选择FALSE项时隐藏整个C列。我们该怎么办呢?本文将向您展示如何使用Excel VBA宏来根据下拉列表框中的选择隐藏或取消隐藏特定列。你只需执行以下步骤;
步骤1:您需要在单元格A2中创建包含TRUE和FALSE项目的下拉列表。 (只需选择数据选项卡,单击数据验证命令,然后在Cell A2中创建一个下拉列表)
步骤2:打开您的Excel工作簿,然后单击开发工具选项卡下的“Visual Basic”命令,或者只需按“ALT + F11”快捷方式。
步骤3:然后将出现“Visual Basic编辑器”窗口。
步骤4:双击VBAProject部分中的当前工作表名称以打开代码窗口。
步骤5:将以下VBA代码粘贴到代码窗口中。然后单击“保存”按钮。
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = ("$A$2") Then If Target.Text = "TRUE" Then Columns("B").EntireColumn.Hidden = True Columns("C").EntireColumn.Hidden = False ElseIf Target.Text = "FALSE" Then Columns("B").EntireColumn.Hidden = False Columns("C").EntireColumn.Hidden = True End If End IfEnd Sub
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PPT怎么为文本添加圆点形项目符号?
![](https://img.aspxhome.com/file/2023/10/a345474_0s.png)
Win10登录界面的密码输入框不见了
![](https://img.aspxhome.com/file/2023/30/a262661_0s.jpg)
Win10怎么更改系统语言?
![](https://img.aspxhome.com/file/2023/1/a277766_0s.jpg)
Win7系统当中的网络协议安装的方法是什么?
![](https://img.aspxhome.com/file/2023/3/a300291_0s.png)
win10新特性 采用更先进的数据压缩技术 给电脑腾出10GB空间
![](https://img.aspxhome.com/file/2023/29/a251453_0s.jpg)
Win10系统改装Win7系统后进不了系统或者安装失败怎么办?
![](https://img.aspxhome.com/file/2023/30/a271065_0s.jpg)
win10系统资讯和兴趣功能无法链接microsoft账户怎么解决?
![](https://img.aspxhome.com/file/2023/1/a276382_0s.png)
XP系统怎样利用写字板创建文档?
![](https://img.aspxhome.com/file/2023/4/a310043_0s.jpg)
wps表格如何乘法运算
Win10专业版声音提示音频服务未响应怎么办
![](https://img.aspxhome.com/file/2023/26/a223267_0s.jpg)
Win10资源管理器怎么打开?五种打开资源管理器的方法
![](https://img.aspxhome.com/file/2023/25/a218030_0s.jpg)
Win7系统如何恢复被删除的文件?
![](https://img.aspxhome.com/file/2023/27/a230284_0s.jpg)
win7如何取消屏保 win7怎么取消屏保
![](https://img.aspxhome.com/file/2023/29/a256654_0s.jpg)
笔记本能换显卡吗?什么笔记本可以更换显卡
![](https://img.aspxhome.com/file/2023/6/a324452_0s.jpg)
电脑死机怎么重装系统Win11 电脑死机重装Win11系统教程
![](https://img.aspxhome.com/file/2023/27/a235707_0s.png)
win10商店下载位置在哪?怎么找到win10商店下载的文件?
![](https://img.aspxhome.com/file/2023/4/47274_0s.jpg)
Word文档更个性 试试这几种输入方法吧
![](https://img.aspxhome.com/file/2023/4/34244_0s.jpg)
word中查看字数信息的方法
![](https://img.aspxhome.com/file/2023/0/29680_0s.jpg)
新用户如何查看苹果/Mac电脑的硬件配置?
![](https://img.aspxhome.com/file/2023/0/a209210_0s.jpeg)
福昕阅读器怎么扫描文件?福昕阅读器的使用教程
![](https://img.aspxhome.com/file/2023/1/a272652_0s.png)