我有以下代码:
Sub level()
x = Range("f1").Value
Select Case x
Case 0 To 4.4
Range("b1").Value = 10
Case 4.4 To 9.4
Range("b1").Value = " B"
Case Else
Range("b1").Value = "false"
End Select
End Sub
它只是一个单元格'F1'。我希望将这些代码用于F1到F365。
我尝试了一些FOR
循环,但没有想要的结果
!! ?? !!
答案 0 :(得分:1)
试试这段代码:
Sub level()
For Each x In Range("F1:F365")
'x.Offset(0, -4) gets B1 for F1, B2 for F2 and so on..'
With x.Offset(0, -4)
Select Case x
Case 0 To 4.4
.Value = 10
Case 4.4 To 9.4
.Value = " B"
Case Else
.Value = "false"
End Select
End With
Next
End Sub
答案 1 :(得分:0)
您可以添加IF
测试,然后转换为值,或者按照以下方式单次执行
Sub Quick()
[f1:f65] = Application.Evaluate("=IF(B1:B365>0,IF(B1:B365>4.4,IF(B1:B365>9.4,""false"",""B""),""10""),""false"")")
End Sub