VBA消息框 - 将代码组合成1个查询 [英] VBA msg box - combining codes into 1 query

查看:88
本文介绍了VBA消息框 - 将代码组合成1个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下VBA编码,适用于1 msg弹出框。但是我想在同一个查询中添加2个其他弹出框,因为我知道这不能超过1,否则我会得到'编译错误'。




*这是VBA,然后在编码之下,我已经把其他细节想要合并*



  Dim xCell As Range,Rg As Range


    On Error Resume Next

   设置Rg = Application.Intersect(目标,范围("A3:A600"))

   如果Not Rg什么都没有那么

       适用于每个xCell In Rg

           如果xCell.Value =" New"然后

                MsgBox"你选择了新的"

               退出Sub

           结束如果

       下一页

   结束如果

End Sub

Private Sub Worksheet_selectionChange(ByVal Target As Range)

   昏暗的xCell作为范围,Rg作为范围

    On Error Resume Next

   设置Rg = Application.Intersect(目标,范围("A3:A600"))

   如果Not Rg什么都没有那么

       适用于每个xCell In Rg

           如果xCell.Value =" New"然后

                MsgBox"以下详细信息是强制性的:" &安培; vbNewLine& "*资金来源" &安培; vbNewLine& "*合同类别" &安培; vbNewLine& "*加拿大或
非加拿大人" &安培; vbNewLine& "*有效开始日期" &安培; vbNewLine& "*有效结束日期" &安培; vbNewLine& "*唯一标识符" &安培; vbNewLine& "*合约价值"

               退出Sub

           结束如果

       下一页

   结束如果

结束子




我希望在此编码中包含(我知道当进入上面的那个时,它看起来不会像这样)



   设置Rg = Application.Intersect(目标,范围("A3:A600"))

   如果Not Rg什么都没有那么

       适用于每个xCell In Rg

           如果xCell.Value =" Amendment"然后

                MsgBox"你选择了修正案"



&



  设置Rg = Application.Intersect(目标,范围("A3:A600"))

   如果Not Rg什么都没有那么

       适用于每个xCell In Rg

           如果xCell.Value ="Old",然后

                MsgBox"你选择了旧的"

解决方案

martin,

re: 您的帖子内容



您发布的第一个代码集没有标题行。

此外,该代码与选择类似改变代码;为什么呢?

I have the following VBA coding which works perfect for 1 msg pop up box. However I want to add 2 other pop up boxes in the same query, as i know this can't be more than 1, otherwise I will get a 'compile error'.

*Here is the VBA, then below the coding, i have put the other details i want to incorporate*

  Dim xCell As Range, Rg As Range

    On Error Resume Next
    Set Rg = Application.Intersect(Target, Range("A3:A600"))
    If Not Rg Is Nothing Then
        For Each xCell In Rg
            If xCell.Value = "New" Then
                MsgBox "You have selected new"
                Exit Sub
            End If
        Next
    End If
End Sub
Private Sub Worksheet_selectionChange(ByVal Target As Range)
    Dim xCell As Range, Rg As Range
    On Error Resume Next
    Set Rg = Application.Intersect(Target, Range("A3:A600"))
    If Not Rg Is Nothing Then
        For Each xCell In Rg
            If xCell.Value = "New" Then
                MsgBox "The following details are mandatory:" & vbNewLine & "* Funding Source" & vbNewLine & "* Contract Category" & vbNewLine & "* Canadian or Non-Canadian" & vbNewLine & "* Effective Start Date" & vbNewLine & "* Effective End date" & vbNewLine & "* Unique Identifier" & vbNewLine & "* Value of contract"
                Exit Sub
            End If
        Next
    End If
End Sub

Want I want to include into this coding is (and I know when this goes into the one above, it wont look like this):

   Set Rg = Application.Intersect(Target, Range("A3:A600"))
    If Not Rg Is Nothing Then
        For Each xCell In Rg
            If xCell.Value = "Amendment" Then
                MsgBox "You have selected amendment"

&

   Set Rg = Application.Intersect(Target, Range("A3:A600"))
    If Not Rg Is Nothing Then
        For Each xCell In Rg
            If xCell.Value = "Old" Then
                MsgBox "You have selected old"

解决方案

martin,
re:  content of your post

There is no title line for the first code set you posted.
Also, that code is similar to the selection change code; why?


这篇关于VBA消息框 - 将代码组合成1个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆