【问题标题】:Search a range for highlighted cells that are not empty在范围内搜索突出显示的非空单元格
【发布时间】:2019-12-01 23:58:22
【问题描述】:

我正在尝试搜索一系列单元格 B2:W6 以查找突出显示的非空单元格并返回这些单元格中的值。我目前不知道如何启动它。

并非所有单元格都突出显示,但如果有一个单元格突出显示且不为空,我想在 msgbox 中返回该值。

突出显示的颜色是通用的黄色突出显示,它是默认的。

类似的东西:

With Range("B2:W6")

If Cell is highlighted and <> "" Then

MsgBox Cell.Value

End If
End With

【问题讨论】:

  • 我没有任何代码我不知道该怎么做。
  • 我只是不知道如何检查单元格是否突出显示
  • 当您检查空字符串时,您还必须在其中包含单元格引用,您不能只输入and &lt;&gt; - 并且您的单元格引用需要被限定。
  • 该链接的信息很少,我认为这不是我要寻找的内容

标签: excel vba


【解决方案1】:

要检查每个单元格,您必须使用 For 循环,您还需要为此声明一个变量“元素”。

然后,对于给定范围内的每个单元格,您要确保它不为空,并且要确保单元格的内部颜色为黄色。

下面的代码应该可以解决问题:

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

【讨论】:

    【解决方案2】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      • 2020-05-19
      • 2020-01-24
      • 2021-12-22
      • 2022-01-10
      • 1970-01-01
      相关资源
      最近更新 更多