Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何从MsgBox中删除变量_Vba_Variables_If Statement - Fatal编程技术网

Vba 如何从MsgBox中删除变量

Vba 如何从MsgBox中删除变量,vba,variables,if-statement,Vba,Variables,If Statement,所以我要做的是把一堆变量传递到If…then语句中。如果该变量返回true,则它将获得“”的值,该值在代码的另一部分中使用。如果返回false,则消息框中将打印不同的值 问题出在这里。有多个变量,当每个变量都打印在消息框中时,它由行分隔。如果一个变量,比如C,返回true,那么它将只是消息框中的一个空白间隔符,其余变量会说些什么。基本上,我正在尝试删除该变量,而不是将其放入消息框中。我怎么能这样做呢 Set cellD = Selection.Find(What:="7/27/2013") If

所以我要做的是把一堆变量传递到If…then语句中。如果该变量返回true,则它将获得“”的值,该值在代码的另一部分中使用。如果返回false,则消息框中将打印不同的值

问题出在这里。有多个变量,当每个变量都打印在消息框中时,它由行分隔。如果一个变量,比如C,返回true,那么它将只是消息框中的一个空白间隔符,其余变量会说些什么。基本上,我正在尝试删除该变量,而不是将其放入消息框中。我怎么能这样做呢

Set cellD = Selection.Find(What:="7/27/2013")
If cellD Is Nothing Then
    D = "7/27/2013, "
Else:
    D = ""
End If

If A = "" And B = "" And C = "" And D = "" Then
    MsgBox (Pass)

Else:
    If A = "" Then Set A = Nothing
    MsgBox ("Missing:" & vbNewLine & A & vbNewLine & B & vbNewLine & C & vbNewLine & D)
这里有一个方法:

Sub test()

Dim output As String

Dim A As String
Dim B As String
Dim C As String
Dim D As String

If A <> "" Then output = A

If B <> "" Then
    If output = "" Then
        output = B
    Else
        output = output & vbNewLine & B
    End If
End If

If C <> "" Then
    If output = "" Then
        output = C
    Else
        output = output & vbNewLine & C
    End If
End If

If D <> "" Then
    If output = "" Then
        output = D
    Else
        output = output & vbNewLine & D
    End If
End If

If output <> "" Then
    MsgBox ("Missing: " & output)
Else
    MsgBox ("Pass")
End If

End Sub
子测试()
将输出设置为字符串
像线一样变暗
将B变暗为字符串
作为字符串的Dim C
将D变暗为字符串
如果A为“”,则输出=A
如果B“那么
如果输出=”,则
输出=B
其他的
输出=输出和vbNewLine&B
如果结束
如果结束
如果是“C”,则
如果输出=”,则
输出=C
其他的
输出=输出&vbNewLine&C
如果结束
如果结束
如果是“D”,则
如果输出=”,则
输出=D
其他的
输出=输出和vbNewLine&D
如果结束
如果结束
如果输出为“”,则
MsgBox(“缺少:”&输出)
其他的
MsgBox(“通行证”)
如果结束
端接头
还有其他方法,但我认为这是一个很好的起点(假设您的VBA技能水平)。我假设A、B和C都是字符串,但您应该根据自己的情况将它们调暗


希望这能让你接近

这里的
A
是什么你测试它,就像它是一个字符串,然后把它设置为“无”,就像它是一个对象。。。有点难理解你的代码-也许再加几行,这样你的意图就更清楚了。谢谢!这帮了大忙@用户3485595太好了,很高兴我能帮上忙。如果解决了您的问题,通常会投票和/或接受解决方案。这让有类似问题的人知道答案是有帮助的。