2012-07-30 5 views
1

J'ai quelques problèmes avec Mod.Mod dans VBA Excel

Mes erreurs Incompability dit

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 

Répondre

1

Mid retourne une chaîne, formater la chaîne à un int/long/double/ect .... flotter

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 
+0

Comme cela? user1564291

+0

ou vous pouvez essayer' Cint (Mid (cellValuekm, 9, 1)) Mod 2 = 0' – Brad

+0

Dident travaille soit. – user1564291