在CInt
中使用VBA
,但有一些空单元格。它需要跳过并转到下一个
Do While i < 400
Str = Cells(i, NOfMonths)
Num = CInt(Str)
If Num > 120 And Num < 500 Then
Cells(i, 13) = ">10"
Else
ws2.Select
On Error Resume Next
result = Application.VLookup(Str, ws2.Range("A3:B125"), 2, False)
If (Err <> 0) Then
Else
ws1.Select
Cells(i, 13) = result
End If
End If
答案 0 :(得分:0)
只需检查单元格是否为空。
Do While i < 400
Str = Cells(i, NOfMonths)
'~~> Check for blank cell
If Len(Trim(Str)) <> 0 Then
Num = CInt(Str)
If Num > 120 And Num < 500 Then
Cells(i, 13) = ">10"
Else
ws2.Select
On Error Resume Next
result = Application.VLookup(Str, ws2.Range("A3:B125"), 2, False)
If (Err <> 0) Then
Else
ws1.Select
Cells(i, 13) = result
End If
End If
End If
Loop
另外请不要将Reserved
个词用作变量。 Str
是保留字。您可以使用Strg
代替。