1

我遇到了一些问题Mod

我的错误说不兼容

Sub test()    
For a = 1 To 5    
Dim cellValuekm As String    
cellValuekm = Range("C1").Offset(a, 0)    
If Mid(cellValuekm, 9, 1) Mod 2 = 0 Then
    Range("G1").Offset(a, 0) = "Kvinna"
Else
    Range("G1").Offset(a, 0) = "Man"
End If    
Next a    
End Sub
4

1 回答 1

1

Mid 返回一个字符串,将字符串格式化为 int/long/double/float 等......

Mid(cellValuekm, 9, 1) Mod 2 = 0 



Sub test()


    For a = 1 To 5
        Dim cellValuekm As String
        cellValuekm = Range("C1").Offset(a, 0)
        If Len(cellValuekm) < 10 Then
            MsgBox "String is less then 10 digits"
        End If            
        If CInt(Mid(cellValuekm, 9, 1)) Mod 2 = 0 Then
            Range("G1").Offset(a, 0) = "Kvinna"
        Else
            Range("G1").Offset(a, 0) = "Man"
        End If
    Next a
End Sub
于 2012-07-30T22:53:24.270 回答