我需要帮助尝试编写excel VBA . 有两个范围,H3:H100和A3:A100
我正在尝试执行以下操作:
在 Workbook open 上,如果范围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”范围内的实际单元格值 .
任何帮助表示赞赏 .
1 回答
在给定行索引的情况下,使用Cells property获取A列中单元格的值:
指数是从1开始的,因此这里的1表示A栏 .