search - VBA conditional search and marking
问题描述
The aim is to search in column A for the word "XXX". When the word is found in that column, the next cell should match the word "C".If it doesn't, carry on with the search for "XXX" in the next row, etc. The issue in my code is that it marks all "C"s. In other words, there is no conditional search where XXX=C.
For Each cell In ws.Range("A1:A20").SpecialCells(xlCellTypeConstants)
Select Case cell.Value2
Case "XXX"
col = RGB(202, 225, 255)
Case Else
col = 0
End Select
If col > 0 Then
wb.Activate
cell.Interior.Color = col
For Each cell2 In cell.Offset(, 2).Resize(1).SpecialCells (xlCellTypeConstants)
res = Switch(cell2.Value = "C", vbGreen)
If Not IsNull(res) Then Intersect(Range("B:B, J:J, L:L, N:N, Q:Q"), Rows(cell2.Row)).Interior.Color = CLng(res) '
Next
End If
Next
解决方案
编辑:见下文
有点不确定你在问什么,但我认为解决方案如下。我使用了更简单的代码,但应该足够了。
For xJ = 1 to 200
If Range("A" & xJ).Value = "XXX" then
Range("A" & xJ).Interior.Color = RGB(202, 225, 255)
If Range("B" & xJ).Value = "C" Then
Range("B" & xJ).Interior.Color = RGB(57, 225, 20)
End If
End if
Next xJ
推荐阅读
- ios - 在 Apple Watch 锻炼期间,您实际上可以获得哪些实时数据?
- java - 我可以使用 map 为 java8 流中的其他对象设置值吗?
- ruby - 如何使用 TCPServer 发送 utf-8?
- sql - 如何在 SQL Server 中执行结束之前开始查看/处理查询结果?
- latex - 如何在 Bookdown 中引用书中的特定章节?
- image - 在来自谷歌电子表格的谷歌文档(或pdf)中插入图像?
- python - avoid duplicated column headers pandas dataframe creation
- python - Python OCR逐行读取PDF文件?
- ios - 为什么当应用程序关闭时,react-navigation 不能从深层链接打开正确的 url?
- electron - circleci 只有 1 个子模式匹配 2