excel - 如何根据excel中另一个工作表单元格值的特定值填充单元格背景颜色?
问题描述
如何根据excel中另一个工作表单元格值的特定值填充单元格背景颜色?
我想根据 Sheet1 单元格值填充 sheet2 单元格。
表 1
表 2
例如,在 sheet1 value 4 missing so 中,不需要像这样填写包含 value 04 的 sheet2 单元格。
请帮我。
解决方案
试一下:
Sub test()
Dim rng1 As Range, rng2 As Range, cell As Range, rngFound As Range
Dim ws1 As Worksheet, ws2 As Worksheet
With ThisWorkbook
Set ws1 = .Worksheets("Sheet1")
Set ws2 = .Worksheets("Sheet2")
End With
With ws1
Set rng1 = .Range("A1:R1")
End With
With ws2
Set rng2 = .Range("A1:E5")
For Each cell In rng2
Set rngFound = rng1.Find(cell.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not rngFound Is Nothing Then
cell.Interior.ColorIndex = rngFound.Interior.ColorIndex
End If
Next cell
End With
End Sub
推荐阅读
- excel - 如何将范围设置为活动列?
- python - 我正在使用 scapy 来获取探测信息。我是 python 新手,也是 scapy
- spring-mvc - 如何使用 Spring MVC 在单个 Jasper 报告中查看两个不同的 jasper 报告?
- c# - 实体框架,通过防止左外连接排序
- android - 找不到元素“菜单”的声明
- c# - 如何使用数据网格添加某个值来更新数据库?
- mysql - mysql计算前行时间戳差异并按多个对象分组
- php - Angular 4/5 中 php getallheaders() 函数的等价物是什么?
- perl - TAP::Harness::JUnit 不会将输出刷新到 STDOUT
- ios - 如何设置设置以获取以 kb 为单位的录制音频文件大小?