mercredi 10 mars 2021

IF with an AND failing in VBA

For some reason my "AND" within an if statement seems to be failing in my VBA code,

Dim c as Integer
c=0
if c = 0 AND "not Delivered" <> "Delivered" And "" = "" Then
   ActiveWorkbook.Worksheets(1).Cells(1, 1).Value = "Add new" 
End if

goes into the if even though c <> 0 so I had to change to this

If c = 0 Then
    If "not Delivered" <> "Delivered" And "" = "" Then
        ActiveWorkbook.Worksheets(1).Cells(1, 1).Value = "Add new" 
    End if
End if

Another example

If CDATE("3/09/2021") <> Date And "1" <> "" Then
    ActiveWorkbook.Worksheets(1).Cells(1, 1).Value = "Add new" 
End if

Goes into even though "1" = "" so having to change to

If CDATE("3/09/2021") <> Date Then
     if "1" <> "" Then
        ActiveWorkbook.Worksheets(1).Cells(1, 1).Value = "Add new" 
     End if
End if

Aucun commentaire:

Enregistrer un commentaire