Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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 对If语句有问题_Excel_Vba - Fatal编程技术网

Excel 对If语句有问题

Excel 对If语句有问题,excel,vba,Excel,Vba,我一直对这个if声明有意见。我试图突出显示一个范围,如果它大于某个数字,则切换数字格式。这是我的密码 wSD2是我的工作表。我只对第一个范围做了一个if语句 With WSD2 If Range(("B3"), ("E" & .Rows.Count)) > 10000 Then .Range(.Range("B2"), .Range("E" & .Rows.Count)).Select Selection.Style = "Comma" S

我一直对这个if声明有意见。我试图突出显示一个范围,如果它大于某个数字,则切换数字格式。这是我的密码

wSD2是我的工作表。我只对第一个范围做了一个if语句

With WSD2

    If Range(("B3"), ("E" & .Rows.Count)) > 10000 Then
    .Range(.Range("B2"), .Range("E" & .Rows.Count)).Select
    Selection.Style = "Comma"
    Selection.NumberFormat = "0,000"
    End If

   .Range(.Range("H2"), .Range("J" & .Rows.Count)).Select
    Selection.Style = "Comma"
    Selection.NumberFormat = "0,000"

    .Range(.Range("F2"), .Range("G" & .Rows.Count)).Select
    Selection.Style = "Percent"
    Selection.NumberFormat = "0.0%"
End With
如果该范围内的数字不大于10000,则不应触及该数字

任何帮助都将不胜感激

谢谢


我想您需要检查该范围内的每个单元格。您还应该直接使用数据,而不是使用
。选择

With WSD2
    For Each cel In .Range(.Range("B3"), .Range("E" & .Range("E" & .Rows.Count).End(xlUp).row))
        If cel.Value > 10000 Then
            cel.Style = "Comma"
            cel.NumberFormat = "0,000"
        End If
    Next cel
...
End With

另外,您的第一个
If
语句没有引用
With
语句。将
添加到将范围“锚定”到
WSD2
。您不能对一系列值使用类似
的操作,您需要逐个循环和测试。工作正常。谢谢!