我正在尝试搜索单元格B2:W6的范围,以查找不为空的突出显示的单元格并返回这些单元格中的值。我目前尚无代码或想法如何开始。
不是所有单元格都突出显示,但是如果有一个单元格突出显示并且不为空,我想在msgbox中返回该值。
突出显示的颜色是通用的黄色突出显示,这是默认设置。
类似的东西:
With Range("B2:W6")
If Cell is highlighted and <> "" Then
MsgBox Cell.Value
End If
End With
答案 0 :(得分:0)
要检查每个单元格,您必须使用For循环,还需要为其声明一个变量“ element”。
然后,对于给定范围内的每个单元格,您要确保其不为空,并且要确保该单元格的内部颜色是黄色。
下面的代码应该可以解决问题:
Sub Name()
Dim element as Variant
For Each element in Range("B2:W6")
If element.Value <> "" and element.Interior.Color = RGB(255,255,0) Then
MsgBox element.Value 'Use this if you want a pop up window for each match
Debug.Print(element.Value) 'Use this to print all results in the Immediate window in VBA (quicker)
End If
Next element
答案 1 :(得分:0)
Dim cell As Range
For Each cell In ActiveSheet.UsedRange
If cell.Interior.Color = vbYellow And cell.Value <> "" Then
MsgBox ("Notify " & cell.Value & " that his time has changed")
End If
Next cell