【发布时间】:2019-04-15 06:32:16
【问题描述】:
目的是在 A 列中搜索单词“XXX”。当在该列中找到该单词时,下一个单元格应与单词“C”匹配。如果没有,请继续在下一行中搜索“XXX”等。我的代码中的问题是它标记所有“C”。换句话说,没有条件搜索,其中 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
【问题讨论】:
标签: search conditional cell background-color