繁体   English   中英

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

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

我需要编程Excel VBA的帮助。 有两个范围,H3:H100和A3:A100

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

打开的工作簿上 ,如果范围为H3:H100的单元格=“ 7天之内允许过期”,则显示一个消息框,显示相应的“ A”列单元格值,并显示:“许可(A列单元格值)在7天内过期”

这是我的代码:

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属性获取A列中单元格的

Cells(cell.Row, 1).Value

索引基于1,因此此处的1表示列A。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM