让Excel活动单元格所在行和列都着上背景颜色的VBA代码
时间:2022-11-24 17:14:17
在Excel中,为了增强活动单元格的对比性,有时候我们常常需要修改其背景颜色、字体、字号等,用来区分和其它单元格的对比!
本教程,让我们一起来学习,如何让Excel活动单元格所在行和列都着上背景颜色,首先看下图。
上图中,即C3单元格,被鼠标选中,说明是活动的单元格,如何做才能做到如上图的效果,C3活动单元格所在的行和列,其背景颜色都着上颜色,这样可以方便我们观察单元格,正确的录入数据。
这得使用VBA代码来完成,方法如下:
首先在Excel窗口中,按下键盘上的组合键:Alt + F11
这个时候,会弹出VBA窗口。
①右键点击左边列表中的 Sheet1 并选中查看代码。这样就会弹出一小个VBA输入窗口。
②在小窗口中的上面,左边选择Worksheet名称,右边选择SelectionChange事件。下面就可以在其内部输入代码了,代码如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Columns().Interior.ColorIndex = 0
x = ActiveCell.Column
Columns(x).Interior.ColorIndex = 13
y = ActiveCell.Row
Rows(y).Interior.ColorIndex = 13
End Sub
最后,保存VBA窗口并关闭,回到Excel窗口,效果就出来了。
知识扩展:
部分代码解释:
Columns().Interior.ColorIndex = 0
x = ActiveCell.Column
Columns(x).Interior.ColorIndex = 13
如上代码的功能,是让活动单元格所在列着上背景颜色的代码。
y = ActiveCell.Row
Rows(y).Interior.ColorIndex = 13
如上代码的功能,是让活动单元格所在行着上背景颜色的代码。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
WPS excel怎样计算反双曲余弦值
![](https://img.aspxhome.com/file/2023/2/a185042_0s.png)
Excel表格使用公式计算一个月多少天教程
![](https://img.aspxhome.com/file/2023/7/a143677_0s.png)
3、输入要搜索的关键字
Win11电脑Explorer.exe占用内存高怎么解决?
![](https://img.aspxhome.com/file/2023/27/a235739_0s.png)
win10系统如何注册ocx文件
![](https://img.aspxhome.com/file/2023/3/a302367_0s.png)
win10系统与win7/win8有哪些区别?
![](https://img.aspxhome.com/file/2023/29/a251336_0s.jpg)
wps如何选定打印区域?
![](https://img.aspxhome.com/file/2023/5/a168535_0s.jpg)
如何设置Excel单元格的输入数据类型限制?
![](https://img.aspxhome.com/file/2023/7/37257_0s.png)
自动循环播放所有幻灯片的设置方法
word英语翻译成中文
![](https://img.aspxhome.com/file/2023/7/34407_0s.gif)
如何一键去除PPT中动画效果?如何保留PPT 中嵌入特殊字体?
![](https://img.aspxhome.com/file/2023/10/a351960_0s.jpg)
Mate Translate支持哪些配对语言
![](https://img.aspxhome.com/file/2023/3/a213033_0s.jpeg)
苹果iOS/iPadOS 15.1正式版发布:支持AirPods 3,带来共享同播及一系列
![](https://img.aspxhome.com/file/2023/1/a283885_0s.jpg)
Windows Lite Santorini现身,Andromeda设备淡出
![](https://img.aspxhome.com/file/2023/3/a300158_0s.jpg)
如何在 Mac 上使用第三方鼠标?
![](https://img.aspxhome.com/file/2023/0/a203550_0s.jpeg)
怎么使用WPS远程连接公司电脑?
![](https://img.aspxhome.com/file/2023/4/a182054_0s.png)
Win10怎么禁用集成显卡?
![](https://img.aspxhome.com/file/2023/4/50604_0s.png)
如何用excel计算乘法的教程
Win10更新显卡驱动提示尝试重启GeForce Experience的解决方法
![](https://img.aspxhome.com/file/2023/3/a299916_0s.jpg)
必应输入法打出不认识的字的方法
![](https://img.aspxhome.com/file/2023/5/a317763_0s.jpg)