如果相应的单元格值等于条件,则显示单元格值的消息框

Display message box of cell value if a corresponding cell value is equal to criteria

我需要帮助来尝试编程 excel VBA。有两个范围,H3:H100 & A3:A100

我正在尝试执行以下操作:

工作簿打开时 ,如果单元格在 H3:H100 = "PERMIT EXPIRES WITHIN 7 DAYS" 范围内,则显示一个消息框显示相应的 "A" 列单元格值说:"Permit (Column A cell value) Expires in 7 days"

这是我的代码:

Private Sub Workbook_Open()
For Each cell In Range("I3:I100")
If cell.Value = "Y" And cell.Value <> "" Then
cell.Interior.ColorIndex = 15
cell.Font.ColorIndex = 10
cell.Font.Bold = True
ElseIf cell.Value = "N" And cell.Value <> "" Then
cell.Interior.ColorIndex = 22
cell.Font.ColorIndex = 2
cell.Font.Bold = True
End If

Next
For Each cell In Range("H3:H100")
If cell.Value = "PERMIT EXPIRES WITHIN 7 DAYS" And cell.Value <> "" Then
MsgBox "Permit (" & cell.Row & ":" & cell.Column & ") Expires in Seven Days", vbExclamation, "Alert"
End If
Next
End Sub

它确实有效,但是它显示相交的行号和列号,而不是 "A" 范围内的实际单元格值。

感谢任何帮助。

在给定行索引的情况下,使用 Cells property 获取 A 列中单元格的

Cells(cell.Row, 1).Value

索引是从1开始的,所以这里的1表示A列。