vba - 如何仅使用循环和 if 语句制作此消息框?
问题描述
Sub RollerCoaster()
Dim strCoaster As String
Dim strType As String
Dim blnFound As Boolean
Dim intWood As Integer
Range("A2").Select
strType = "Wood"
blnFound = False
Do Until ActiveCell.Value = ""
strCoaster = ActiveCell.Offset(1, 0).Value
If ActiveCell.Offset(0, 2).Value = strType Then
strCoaster = ActiveCell.Value
MsgBox ("The RollerCoaster made out of woods is " & strCoaster)
blnFound = True
Exit Do
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub
我知道如何只为 1 个过山车循环,但我怎样才能在消息框中获取所有 Wood 类型的过山车?
解决方案
像这样的东西(不需要选择/激活)
Sub RollerCoaster()
Dim strType As String
Dim c As Range, msg
strType = "Wood"
msg = ""
Set c = ActiveSheet.Range("A2")
Do While Len(c.Value) > 0 = ""
If c.Offset(0, 2).Value = strType Then
msg = msg & vbLf & c.Value
End If
Set c = c.Offset(1, 0)
Loop
If Len(msg) > 0 Then Msgbox "Found matches:" & msg
End Sub
推荐阅读
- python - Pyglet.clock.schedule 显着函数调用速度限制
- node.js - React - 无法访问服务器端的环境变量
- haskell - Cabal 升级时的意外行为
- swift - Swift 开放 API 线程
- java - 使用java从单个rabbit MQ队列中检索多条消息
- python - 具有感应频率的简化 Lesk 算法
- python - DFS 会访问所有顶点吗?
- php - 在 Woocommerce 的 Orders 元框中添加一个新块
- amazon-web-services - 不推荐使用 interceptApplication(_:didFinishLaunchingWithOptions:)'
- pact-broker - 如何创建可以由协议代理中的 Provider_verification_published 事件触发的有效 webhook?