我如何用Just循环和if语句制作此消息框?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我如何用Just循环和if语句制作此消息框?相关的知识,希望对你有一定的参考价值。

enter image description here

        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语句制作此消息框?的主要内容,如果未能解决你的问题,请参考以下文章

我如何用 pafy 为进度条制作线程

如何用一个 if 语句替换此代码? [关闭]

如何用java中的星号制作盒子?嵌套循环?

如何用Python for循环语句,if语句 计算1-2+3-4+5......-99

基于if语句的for循环,错误消息= Series的真值不明确[重复]

如何用Selenium IDE 实现简单的循环和条件语句