最佳答案
我需要将 VBA 中从 excel 获得的字符串转换为整数。为了这样做,我使用 CInt()
工作得很好。但是,字符串有可能不是数字,在这种情况下,我需要将整数设置为0。目前我有:
If oXLSheet2.Cells(4, 6).Value <> "example string" Then
currentLoad = CInt(oXLSheet2.Cells(4, 6).Value)
Else
currentLoad = 0
End If
问题是,我不能预测所有可能的非数字字符串可能在这个单元格中。有没有一种方法,我可以告诉它转换,如果它是一个整数,并设置为0,如果没有?