Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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 检查行中是否有负值_Excel_Vba - Fatal编程技术网

Excel 检查行中是否有负值

Excel 检查行中是否有负值,excel,vba,Excel,Vba,我试图使用以下vba代码检查Excel工作表第1行中的负值,数字为1,2,-3,4,5,6。宏应选择-3值并停止。不幸的是,它不起作用。出现一个错误,告诉我结束If而不使用block If。我看不出我的错误 Sub SelectNegativeValue() Dim Cell As Range For Each Cell In Range("1:1") If Cell.Value < 0 Then Cell.Select Exit

我试图使用以下vba代码检查Excel工作表第1行中的负值,数字为
1,2,-3,4,5,6
。宏应选择
-3
值并停止。不幸的是,它不起作用。出现一个错误,告诉我
结束If而不使用block If
。我看不出我的错误

Sub SelectNegativeValue()
    Dim Cell As Range

    For Each Cell In Range("1:1")
        If Cell.Value < 0 Then Cell.Select
            Exit For
        End If
    Next Cell
End Sub
Sub-SelectNegativeValue()
暗淡单元格作为范围
对于范围内的每个单元格(“1:1”)
如果Cell.Value<0,则选择Cell.Select
退出
如果结束
下一个细胞
端接头
宏应选择“-3”值并停止

您需要移动
单元格。选择
到下一行。。。就在退出之前

Dim Cell As Range
For Each Cell In Range("1:1")
    If Cell.Value < 0 Then
        Cell.Select
        Exit For
    End If
Next Cell
Dim单元格作为范围
对于范围内的每个单元格(“1:1”)
如果单元格值<0,则
单元格。选择
退出
如果结束
下一个细胞

学会正确缩进代码,您将看到错误

如果有一个
If
语句在
之后有代码,那么
在同一行中,这意味着它是一个单行
If
语句,不允许在
结束If
时有
结束

End如果
用于多行
如果
语句不允许在
之后有代码,则
在同一行中:

Sub SelectNegativeValue()
    Dim Cell As Range
    For Each Cell In Range("1:1")
        If Cell.Value < 0 Then 
            Cell.Select
            Exit For
        End If
    Next Cell
End Sub
Sub-SelectNegativeValue()
暗淡单元格作为范围
对于范围内的每个单元格(“1:1”)
如果单元格值<0,则
单元格。选择
退出
如果结束
下一个细胞
端接头