我如何用Just循环和if语句制作此消息框?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我如何用Just循环和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
另一答案
这里您要我显示...
Dim MyType As Variant
MyType = Array("Wood", "Soil", "Cement", "Brick")
For mycnt = 1 To UBound(MyType)
strType = MyType(mycnt - 1)
blnFound = False
'Your do loop here
Next
以上是关于我如何用Just循环和if语句制作此消息框?的主要内容,如果未能解决你的问题,请参考以下文章
如何用Python for循环语句,if语句 计算1-2+3-4+5......-99