vba - 如果范围有特定注释,则在另一个单元格中显示 msg
问题描述
我在 VBA 中有这段代码,并要求它在另一张纸上显示“最终装瓶”。下面是代码
Ip = input worksheet
op1 = Checks worksheet
i = 1
Cell = Ip.Cells(9, i + 2)
If LCase(Left(Cell, 14)) = "final bottling" Then
'#Checks Final Bottling
Op1.Cells(8, 5) = "Final Bottling Run, Please Consume materials. If unsure, check with materials planner!"
Else
Op1.Cells(8, 5) = ""
End If 'Check
如果 C9:H9 范围内的所有评论都有评论“最终装瓶”,则会出现该消息。但是,如果该范围内只有一个单元格具有注释,它将不再出现。不知道现在该怎么做,如果这听起来很愚蠢并且必须是一个简单的解决方案,请道歉
解决方案
如果 Ip 中 C9:H9 中的任何单元格具有“最终装瓶”,这将显示消息
Sub Test()
Dim i As Long
Dim checkCell As Range
Set checkCell = op1.Cells(8, 5)
For i = 3 To 8
Debug.Print LCase(Left$(Ip.Cells(9, i).Value, 14))
If LCase(Left$(Ip.Cells(9, i).Value, 14)) = "final bottling" Then
checkCell.Value = "Final Bottling Run, Please Consume materials. If unsure, check with materials planner!"
Exit Sub 'Check is complete, exit sub from here
End If
Next i
checkCell.Value = vbNullString 'code will only pass here if it fails all the check in the loop above.
End Sub
推荐阅读
- python - 为什么我必须调用 model.predict(x) 而不是 model(x)?
- python - 同时运行多个 Python 脚本的性能
- javascript - 如何使用Javascript在HashMap中基于不区分大小写的键查找值
- html - 如何让 CSS 打字机效果工作?
- python - 在字符串周围画一个简单的框
- sapui5 - 如何使用 UI5 诊断识别损坏的绑定
- java - MacOS Catalina 是否会剥离 zip 文件中的可执行文件权限?
- html - 有没有办法为列表样式图像添加边距或填充?
- swift - 快速生成 STL 缩略图
- javascript - Slick Slider 按类别过滤