Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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
Excel VBA,当单元格中的文本更改为“时如何循环Msgbox”;新闻";在下一栏中回答Msgbox的问题_Vba_Excel_Loops_Text_Msgbox - Fatal编程技术网

Excel VBA,当单元格中的文本更改为“时如何循环Msgbox”;新闻";在下一栏中回答Msgbox的问题

Excel VBA,当单元格中的文本更改为“时如何循环Msgbox”;新闻";在下一栏中回答Msgbox的问题,vba,excel,loops,text,msgbox,Vba,Excel,Loops,Text,Msgbox,我试图创建一个MsgBox,当一列中的单元格从空白变为“新闻”时,它会自动弹出“是或否”的提示,并将答案放入下一列 随着时间的推移,我将继续添加到行中,因此当单元格从空白变为“新闻”时,它必须自动弹出,并将答案输入到右侧新添加的单元格中 我很确定我需要For-each循环,但老实说,我有点迷路了,在If相交线的调试过程中出现了一个不匹配错误 Private Sub Worksheet_Change(ByVal Target As Range) Dim myRange As Range Set

我试图创建一个MsgBox,当一列中的单元格从空白变为“新闻”时,它会自动弹出“是或否”的提示,并将答案放入下一列

随着时间的推移,我将继续添加到行中,因此当单元格从空白变为“新闻”时,它必须自动弹出,并将答案输入到右侧新添加的单元格中

我很确定我需要For-each循环,但老实说,我有点迷路了,在If相交线的调试过程中出现了一个不匹配错误

Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRange As Range

Set myRange = Range("G2:G1000")

If Intersect(myRange, Target) Then


If Range("G2").Value = "News" Then Answer = MsgBox("Good?", vbYesNo)
    Answer = ActiveCell.Offset(0, 1) = 1 'not sure if this is right, or is it Range.Offset?

Dim cel As Range
For Each cel In Range("G2:G1000")

    If cel.Value = "News" Then Answer = MsgBox("Good?", vbYesNo)
    Answer = ActiveCell.Offset(0, 1) = 1 'not sure if this is right, or is it Range.Offset?
    Exit For

Next

End If

End Sub
给你:

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Column = 7 Then
        If Target.Count = 1 Then
            If LCase$(Target) = "news" Then
                Application.EnableEvents = False
                Target(, 2) = Array("Yes", "No")(MsgBox("Good?", vbYesNo) - 6)
            End If
        End If
    End If
    Application.EnableEvents = True
End Sub
给你:

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Column = 7 Then
        If Target.Count = 1 Then
            If LCase$(Target) = "news" Then
                Application.EnableEvents = False
                Target(, 2) = Array("Yes", "No")(MsgBox("Good?", vbYesNo) - 6)
            End If
        End If
    End If
    Application.EnableEvents = True
End Sub

“老”消息呢?你想每次都在所有行上运行吗?那“旧”新闻呢?你想每次都在所有行上运行吗?哇,非常感谢你的快速回答!它工作得很好。。我挣扎了一会儿,加油!哇,非常感谢你的快速回答!它工作得很好。。我挣扎了一会儿,加油!