首页 > 解决方案 > 如何将弹出窗口中的 ID 与 Excel 中的 VBA 对齐?

问题描述

我在 Excel 2010 中有一个数据库,列出了不同的测量设备。每件作品都有一个 ID,还有一些其他的东西是已知的。

Each entry line looks like this:
ID    …     …   Need for a pop-up?
1     …     …         NO
2     …     …         YES
3     …     …         NO
4     …     …         NO

等等。

出于可用性或功能等信息,我创建了一个公式来总结这些信息,并对以下问题给出“是”或“否”的答案:“需要弹出警告吗?” 因此,每当有人想借出可能无法工作/不可用的设备时,应通过弹出窗口警告用户:“警告:ID 为 111 的设备。此仪表可能有缺陷/不可用。 "

我已经有一些代码,每次出现以下问题时都会给我一条弹出消息:“需要弹出窗口”回答为“是”,但我无法在弹出窗口的文本中对齐受影响部分的 ID -向上。

Sub POP_UP_if_defect()

    'In Cells N6:N500 are the answers "YES" or "NO" listed

    For Each Cell In Sheets ("Sheet X").Range("N6:N500")
        If Cell.Value = "YES" Then
            MsgBox "Warning: This device might be defect/not available!"
        End If
    Next
End Sub

提前感谢您对此提供的任何帮助!

标签: excelvba

解决方案


cell包含“YES”时,您必须从该行的“A”列获取 id。尝试这样的事情:

With Sheets("Sheet X")
    For Each cell In .Range("N6:N500")
        If cell.Value = "YES" Then
            Dim id
            id = .Cells(cell.row, 1)
            MsgBox "Warning: device " & id & " might be defect/not available!"
        End If
    Next cell
End With

推荐阅读