Excel 对If语句有问题
我一直对这个if声明有意见。我试图突出显示一个范围,如果它大于某个数字,则切换数字格式。这是我的密码 wSD2是我的工作表。我只对第一个范围做了一个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
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
。您不能对一系列值使用类似
的操作,您需要逐个循环和测试。工作正常。谢谢!