excel - 如果单元格的文本中有特定单词,则突出显示该单元格
问题描述
我想红色突出显示包含“颜色”和“宽度”一词的所有单元格。
使用我拥有的代码,我输入单元格的值。我想输入单词“颜色”和“宽度”。
Sub test()
aaa = InputBox("Enter value 1:")
bbb = InputBox("Enter value 2:")
Dim myrange As Range
Set myrange = ThisWorkbook.Worksheets("Tabell").UsedRange
For Each cell In myrange.Cells
If cell.Value = aaa Or cell.Value = bbb Then
cell.Interior.Color = 255
End If
Next
End Sub
解决方案
您可以使用Like
.
编辑- 更新以允许输入多个术语(未经测试)
dim terms as new collection, term, deleteMe as boolean
do
term = Trim(InputBox("Enter value (leave blank to end entry)"))
if len(term)>0 then
terms.add term
else
exit do
end if
loop
if terms.count=0 then exit sub '<< no terms to check for
For Each cell In myrange.Cells
deleteMe = true
for each term in terms
if not cell.value like term & "*" then
deleteMe = false
exit for
end if
next term
if deleteMe then cell.value = ""
next cell
推荐阅读
- arrays - 什么时候用方括号,什么时候用圆括号?
- php - 在 wordpress 和 woocommerce 上为菜单项设置唯一类
- java - 打印每个请求的请求 ID
- opencv - 如何在 OpenCV cv::cuda::GpuMat 或 cv::ogl::Buffer 图像对象上绘制文本和矩形?
- parsley.js - 如何使用 parsley.js 验证整个表单
- django-queryset - Django Queryset 将每个用户与组结合起来?
- php - AJAX图片上传FormData问题
- c# - 检索具有相同 HotelID 的数据
- java - Springcloud多数据源@RefreshScope报错
- python - 如果阻塞程序将无法进入