单击消息框后,它应该将我定向到输入框

  • 本文关键字:消息 单击 vba excel
  • 更新时间 :
  • 英文 :


这是我Inputbox代码:

Private Sub Q1No_Click()
    Dim myResponse As String
    myResponse = InputBox("Reason for not atten Morning MOM", "Mention Reason", 0, 0)
    Range("G4") = myResponse
End Sub

这是我Msgbox代码:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
    Set rng = Range("C22")
    If Application.Intersect(Target, rng) Is Nothing Then
        MsgBox "You must select the answer from the list" 
    End If

如何链接这两者?

可能是这样的:

Private Sub Q1No_Click()
    Dim myResponse As String
    Do
        myResponse = InputBox("Reason for not atten Morning MOM", "Mention Reason", 0, 0)
        If myResponse = "" Then MsgBox "mention the reason"
    Loop While myResponse = ""
    Range("G4") = myResponse
End Sub

根据您的评论,请试试这个:

Sub marine()
    Dim myprompt As String, myresponse As String
    myprompt = "Reason for not attending morning MOM:"
    With Sheet1 '/* this is your sheet */
        Do
            myresponse = InputBox(myprompt, "Mention Reason")
            myprompt = "No reason provided." & vbNewLine & _
                       "Please provide a reason and try again."
        Loop Until Len(myresponse) > 0
        .Range("G4").Value2 = myresponse
    End With
End Sub

这将强制在Inputbox上放一些东西。
我放弃了Msgbox的使用,并在用户没有在上面放任何东西时修改了Inputbox的提示。

最新更新